Break Statement

Break Statement

A break statement exits a loop immediately, regardless of its condition. Execution continues on the first line after the loop.

This page covers the break statement in the context of loops. For an introduction to loops, see Loop.

Breaking Out of a Loop#

The most common use is inside a while loop to stop based on something that happens inside the loop body, rather than the condition at the top: