Click to see full answer
If so, the break statement terminates both loops and passes the control over the next statement following the loop.
Herein, does break Statement break out of all loops?
A break statement in a loop (if the break is not part of a switch case) always breaks out of only the loop in which the break is executed. If C is nested inside B, and B is nested inside A, then: A break statement inside loop C will break out of loop C, but you'll still be inside loop B.
How do you break out of multiple loops?
Breaking out of two loops
- Put the loops into a function, and return from the function to break the loops.
- Raise an exception and catch it outside the double loop.
- Use boolean variables to note that the loop is done, and check the variable in the outer loop to execute a second break.