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…
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.
break and continue hit the nearest loop, unless you name one
break outer does nothing, or fails with "label not found" The label must sit right in front of the loop statement you mean, and that loop must enclose the break: outer: for (…). Not inside the loop body, not on the wrong loop. With no loop of that name, the engine refuses the program: SyntaxError: Undefined label 'outer'.return: the intent is clearer.break in the inner loop thought to stop everything, while the outer loop goes on break leaves only the nearest loop. To leave the outer loop too, give it a label and use break label, or move the loops into a function and return.break: the outer loop goes on The first open door only ends that gang: the neighbourhood head goes on to the next gang and finds another.break ronda As soon as he finds an open door, both loops end. The other doors fade: never tried.continue with continue ronda continue: on to the next door, the open one not written down safe. continue ronda: straight to the next gang, gangAman skipped too.ronda: label, keep break ronda The engine refuses the program before a single line runs: SyntaxError: Undefined label.