Using Loop constructs with embedded switch statements
Posted: Mon Jul 25, 2016 4:22 pm
				
				Hi Admin,
One more small query.I executed the below:
I was wondering what would be the value of i being passed.The question might seem bad coding but i was curious to find value of i which instead of being passed as i=6 was passed as 0 for iteration!
If the variables in switch statements are compile time constants then i would assume that i=6 is also being assigned at compile time as it is assigned to a fixed value. Please help.
			One more small query.I executed the below:
Code: Select all
LOOP: for (i = 0; i <= 5; i++) {
			switch (i = 6) {
			case '0':
				System.out.println("A");
			case 1:
				System.out.println("B");
				break LOOP;
			case 2:
				System.out.println("C");
				break;
			case 3:
				System.out.println("D");
				break;
			case 4:
				System.out.println("E");
			case 'E':
				System.out.println("F");
			}
		}
If the variables in switch statements are compile time constants then i would assume that i=6 is also being assigned at compile time as it is assigned to a fixed value. Please help.