Site hosted by Angelfire.com: Build your free website today!



Next: The continue Statement Up: Control of Your Previous: The for Loop

The break Statement

We have already met break in the discussion of the switch statement. It is used to exit from a loop or a switch, control passing to the first statement beyond the loop or a switch.

With loops, break can be used to force an early exit from the loop, or to implement a loop with a test to exit in the middle of the loop body. A break within a loop should always be protected within an if statement, this provides the test to control the loop exit condition.