Labeled Statement block in Java?

后端 未结 4 1214
后悔当初
后悔当初 2020-11-29 11:39

I was browsing through some of the base Java objects when I found a section of code surrounded by a scan: {} block. The following code is from the toLowerCase()

4条回答
  •  渐次进展
    2020-11-29 12:00

    Here, scan: is simply a label. The break 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.

提交回复
热议问题