Hello everybody.
Consider this code:
public class
Test {
public static void main(
String st[]){
l1:
for(int i=4; i<=7; i++)
switch(i){
default:{System.out.println("default");}
case 4: {System.out.println("case 4");}
break;
case 5: {System.out.println("case 5");} break l1;
case 6: {System.out.println("case 6");}
case 7: {System.out.println("case 7");}
}
}
}
The above code gives the output :
case 4
case 5
However, according to me case 6 should also be displayed. And if default clause is the first statement in the Switch statement, why it is not executed. Could you please tell me the reason?