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


Whereisstuff is simple learing platform for beginer to advance level to improve there skills in technologies.we will provide all material free of cost.you can write a code in runkit workspace and we provide some extrac features also, you agree to have read and accepted our terms of use, cookie and privacy policy.
© Copyright 2024 www.whereisstuff.com. All rights reserved. Developed by whereisstuff Tech.