Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 2.6 — break, continue and Labels
JavaScript · Example 3 of 3

break inside a switch inside a loop

A plain break in a switch only leaves the switch. continue rows skips straight to the next row, so only row 3 reaches its last line.

break leaves a loop (or switch) immediately, continue skips the rest of the current iteration and moves on to the next one, and a label lets either of them act on an outer loop instead of the innermost one.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 5 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Loop over [5, 12, 8, 130, 44] and print the first number greater than 100, then stop.

02

Print every number from 1 to 10 except multiples of 3, using continue.

Explain it without notes

01

What is the difference between break and continue?

02

What does a plain break do inside nested loops, and how do you leave both loops?

03

Why can't you use break inside forEach?

break inside a switch inside a loop

Console

(nothing was printed)

Expected console output

quit seen, total so far: 2
final total: 2
row 3 complete: 123