3 min read
break / continue
Prerequisites: for loops, while loops
break exits a loop immediately. continue skips the rest of the
current iteration and moves to the next one.
for (let n = 0; n < 10; n++) {
if (n === 5) break; // stop the loop entirely
if (n % 2 === 0) continue; // skip even numbers, keep looping
console.log(n);
}
Expected output
1
3