Labeled Loops: break/continue the Outer Loop

The neighbourhood head’s round walks three gangs of row houses door by door: an open door fires break, continue, break ronda or continue ronda, and where the…

Why it matters

Searching two-dimensional data (a table, a matrix, a grid) is everyday work. When you find it, you often want to stop, but break in the inner loop does not stop the outer one. Without labels people add a flag variable or split the code into a function just to return. A label turns "get all the way out" into one readable line.

The key idea

break and continue hit the nearest loop, unless you name one

Common mistakes

Try it in this playground