JavaScript - Break & Continue
Overview
Estimated time: 10–15 minutes
break
exits a loop early; continue
skips to the next iteration.
Learning Objectives
- Use
break
andcontinue
to control loop flow. - Avoid overuse that harms readability.
Prerequisites
Examples
for (let i = 0; i < 5; i++) {
if (i === 3) break; // exit loop
if (i % 2 === 0) continue; // skip even
console.log(i); // 1
}
Common Pitfalls
- Nested loops with many breaks/continues can be hard to follow; refactor into functions when possible.