I don't understand the output of the following code:
public class testBreak
{
public static void runTest()
{
high_level:
{
System.out.println("\nEnter in High Level");
middle_level:
for(int i = 0; i < 4; i++)
{
System.out.println("Enter in Middle level cicle");
int j = 0;
low_level:
while(j++ < 2)
{
System.out.println("Enter in Low level cicle");
System.out.println("i = " + i + ";j = " + j);
switch(i)
{
case 0 : break;
case 1 : break low_level;
case 2 : break middle_level;
case 3 : break high_level;
}
System.out.println("Exit from Low level cicle");
}
System.out.println("Exit from Middle level cicle");
}
System.out.println("Exit from High level cicle");
}
}
public static void main(String args[])
{
runTest();
}
}
Here is the output:
Enter in High Level
Enter in Middle level cicle
Enter in Low level cicle
i = 0;j = 1
Exit from Low level cicle
Enter in Low level cicle
i = 0;j = 2
Exit from Low level cicle
Exit from Middle level cicle
Enter in Middle level cicle
Enter in Low level cicle
i = 1;j = 1
Exit from Middle level cicle
Enter in Middle level cicle
Enter in Low level cicle
i = 2;j = 1
Exit from High level cicle
I understand up to the line i = 1;j = 1
but why does it go to Exit from Middle level cicle
and not to Enter in low level cicle
because we have j = 1 and while(j++ < 2) should take 1 < 2, then increase j to 2 and enter the low level cicle as it did in the first run??
editet: It seems break with label does not equal goto, it breaks out of the labeled loop? and the loop is not free in the code like in C/C++, but it is applied to that particular loop?