In JavaScript loops, break and continue are control statements that alter the normal flow of iteration.

💡 What do they do?
break: Immediately exits the entire loop.continue: Skips the current iteration and moves to the next one.
How break works
The break statement stops the loop entirely when executed.
📌 Deep Dive: Using break
JAVASCRIPT
for (let i = 1; i <= 5; i++) {
if (i === 3) {
break; // Exit loop when i equals 3
}
console.log(i);
}
Output
12
How continue works
The continue statement skips the rest of the current loop iteration and proceeds with the next iteration.
📌 Deep Dive: Using continue
JAVASCRIPT
for (let i = 1; i <= 5; i++) {
if (i === 3) {
continue; // Skip the rest when i equals 3
}
console.log(i);
}
Output
12
4
5
Comparison:
break vs continue| Feature | break | continue |
|---|---|---|
| Effect on Loop | Terminates loop completely | Skips current iteration only |
| Next step | Exit loop | Proceed to next iteration |
| Common use case | Stop loop when condition met | Ignore certain values or steps |
⚠️ Important Note
Using break or continue outside loops will cause syntax errors. They only work inside for, while, or do...while loops.
Summary
breakstops and exits the entire loop immediately.continueskips the rest of the current loop iteration and moves on.- Both help control loop execution flow based on conditions.
Quick Knowledge Check
Test what you just learned
Question 1 of 2
What does continue do inside a loop?
Question 2 of 2
What happens when a break statement runs inside a loop?
0/2
Loading results...