Advertisement

Google Ad Slot: content-top

JS Break and Continue


break Statement:

The break statement is used to exit from a loop prematurely. When a break statement is encountered inside a loop, the loop will stop executing.

Example
for (let i = 0; i < 10; i++) {
if (i === 5) {
break; // Exits the loop when i equals 5
}
console.log(i);
}
Try it yourself

continue Statement:

The continue statement is used to skip the current iteration of a loop and move to the next iteration.

Example
for (let i = 0; i < 10; i++) {
if (i === 5) {
continue; // Skips the current iteration when i equals 5
}
console.log(i);
}
Try it yourself