Labeled Statement block in Java?

Here, scan: is simply a label. The break <label> syntax allows one to break out of outer loops, and to simulate some forms of the goto statement. The syntax is documented in the JLS:

A break statement with label Identifier attempts to transfer control to the enclosing labeled statement (ยง14.7) that has the same Identifier as its label; this statement, which is called the break target, then immediately completes normally. In this case, the break target need not be a switch, while, do, or for statement.

Leave a Comment