Return to site

☕ JAVA TRICK: Labeled breaks and continues

· java

You know to use the 'break' statement to get out of a loop, but did you know that

you can give it a label to break out of an appropriately labeled outer loop as well?

Likewise with 'continue', which skips the rest of current iteration of the innermost loop:

if you pass it a label, it will skip the iteration of the labeled instead.

But as always, just because you can, doesn't mean you should!