nested loops, e.g. in Java we may write:
As you can see first we label outer for loop with
OUTER_LOOP label, then we use
break label_name syntax to tell compiler which loop we want to break.
both programs will print:
TIP: You can use
continue instead of
break and it will work too.
I think most of you knew this already, but what’s more interesting is that you can break
out of any nested code block, for example in Java:
this program will print when run:
Ability to break nested loops and to jump out of nested code blocks is not
something that you do on everyday job, but once in a year it may become handy.
Just remember to not overuse it (from XKCD):