5.7. break and continue Statements

In addition to selection and repetition statements, Java provides statements break and continue (presented in this section and Appendix K, Labeled break and continue Statements) to alter the flow of control. The preceding section showed how break can be used to terminate a switch statement’s execution. This section discusses how to use break in repetition statements.

Java also provides the labeled break and continue statements for use in cases in which you need to conveniently alter the flow of control in nested control statements. We discuss the labeled break and continue statements in Appendix K.

break Statement

The break statement, when executed in a while, for, do...while or switch, causes immediate exit ...

Get Java™ How to Program, Seventh 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.