Question about com.enthuware.jfcja.v8.2.292
Posted: Wed Jul 19, 2023 7:04 pm
For a nested loop with a break in its innermost loop, I am confused about the initialization. From the answer to this question and answer, it appears that the innermost loops (j, k) re-initialize to zero rather than maintain the iteration it had prior to the break. Is there a source where this situation (why the inner loops are re-initialized after a break) is explained.
Code: Select all
class LoopTest
{
public static void main(String [] args)
{
int counter = 0;
outer: for(int i = 0; i < 3; i++)
for(int j = 0; j < 3; j++)
for(int k = 0; k < 3; k++)
{
if(k - j > 0) break middle;
counter++;
}
System.out.println(counter);
}
}