Command Palette

Search for a command to run...

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

break and continue in a shopping list

Empty entries are skipped with continue; STOP ends the loop with break, so chips and cola never appear.

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 and continue in a shopping list

Preview

Press Run to see the page.

Console

Nothing logged yet.

Expected console output

skip empty at 1
skip empty at 3
break at 5
items on the page: 3