Break and Continue

This lesson discusses the break and continue construct in detail.

Introduction

Sometimes, we may want to skip the execution of a loop for a certain condition or terminate it immediately without checking the condition. To specifically change the flow of execution, we have another two statements, break and continue.

break statement

In every iteration, a condition has to be checked to see whether the loop should stop. If the exit-condition becomes true, the loop is left through the break statement. A break statement always breaks out of the innermost structure in which it occurs; it can be used in any for-loop (counter, condition, and so on), but also in a switch, or a select statement. Execution is continued after the ending } of that structure. The following figure explains the break statement.

Get hands-on with 1400+ tech skills courses.