freecoding.school100% FREE · NO SIGNUP
Script SpringsISSUE #29 of 29

break · continue · labels

SparkyVSNaN the Trickster
Sparky saysbreak exits a loop early; continue skips to the next iteration; labels target outer loops.

break stops a loop entirely; continue skips the rest of the current iteration. For nested loops, a label (outer: for(...)) lets break outer or continue outer target the named loop. Labels are rare — often a sign you should extract a function instead.

Power-ups you unlock

NaN the Trickster attacks — common mistakes

Boss battleLoop 1–10, skip multiples of 3 with continue, and break at 8.

Example code

<!doctype html><html><head><meta charset="utf-8"></head>
<body style="background:#06040d;color:#e6e0ff;font-family:monospace;padding:20px"><pre id="o"></pre>
<script>let out=[]; for(let i=1;i<=10;i++){ if(i%3===0) continue; if(i===8) break; out.push(i); }
document.getElementById('o').textContent=out.join(' ');</script></body></html>
▶ Open the interactive comic issue
‹ While · Do-While