Break statement

The break statement is used to jump out of a loop. It can be used to “jump out” of a switch() statement. It breaks the loop and continues executing the code after the loop.

Example:

Javascript




let content = "";
let i;
for (i = 1; i < 1000; i++) {
    if (i === 6) {
        break;
    }
    content += "Geeks" + i + "\n"
}
console.log(content);


Output

Geeks1
Geeks2
Geeks3
Geeks4
Geeks5

JavaScript break and continue

Similar Reads

Break statement

The break statement is used to jump out of a loop. It can be used to “jump out” of a switch() statement. It breaks the loop and continues executing the code after the loop....

Continue statement

...

JavaScript labels

The continue statement “jumps over” one iteration in the loop. It breaks iteration in the loop and continues executing the next iteration in the loop....

Contact Us