break Statement
The break
statement, when executed in a while
, for
, do
...while
or switch
, causes immediate exit from that statement. Execution continues with the first statement after the control statement. Common uses of the break
statement are to escape early from a loop or to skip the remainder of a switch
(as in Fig. 5.9). Figure 5.13 demonstrates a break
statement exiting a for
.
Get Java™ How To Program (Early Objects), Tenth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.