Within loops (such as a while loop) you can use the break statement to exit the loop immediately.

It only exits out of the innermost loop

break;

The break statement is also a critical component of most switch statements. It prevents code in subsequent code sections from being executed, which is usually a programmer's intent, by immediately exiting the switch statement. Missing break statements in a switch are a frequent source of hard-to-find bugs.