You have already seen the branching statements break and return in our examples. We will define and discuss them and the third member of the group—the branching statement continue —in this section.
Branching statements
Break and labeled break
As you have probably noticed, the break statement is essential for the switch...case selection statements to be able to work (see the switch...case section for more information). If included in the execution block of an iteration statement, it causes the for or while statement to terminate immediately.
It is widely used in iteration statements while searching for a particular element in an array or collection. To demonstrate how it works, let's assume, for example...