[Solved] Labeled Continue statement fails to compile


Your out label “annotates” this for-loop:

out:
for(i = 0 ; i <= 6 ; i++)
{
    System.out.println(i);
}

So in order to continue with the label out, it would need to be within that for-loop. It doesn’t make sense to use it after that for-loop has ended. This will compile, for example:

out:
for(int i = 0; i <= 6; i++)
{
    System.out.println(i);
    continue out;
}

In this case, you do not need a labeled continue statement, however. There is no ambiguity. There’s only one loop that can be “continued” out of.

The Oracle tutorial explains it nicely.


It’s worth mentioning that I can’t even remember the last time I had to use labeled continue – maybe never. I would avoid them unless you have almost no other choice.

3

solved Labeled Continue statement fails to compile