The break statement
The break statement is used to easily exit any loop early. With the help of the break statement loops can easily be stopped at a specific position.
Flow chart for break statement
The below example shows how a break statement can be used to exit a loop thereby stopping the loop from getting to the end.
The continue Statement
The continue statement is similar to the break statement but over here the loop skips a particular iteration and continues looping till the end. If we are to print out numbers from 1-10 we can use the continue statement to skip printing any number e.g number 6. while the remaining numbers gets printed. for example printing 1,2,3,4,5,7,8,9,10.
Controlling Loops Using Labels
A label is simple identifier with a colon (:) that is applied to a statement or a block of code in order to identify that block of code and control the loop block of code when needed.
Labels can be used to control loops also with the help of the break and continue statements. With labels we can easily run two loops simultaneously without encountering problems.
Examples of looping using labels