JavaScript · JS Tutorial · Lesson 32
JS Break
break and continue in loops.
The break statement jumps out of a loop. The continue statement skips the current iteration and continues with the next one.
Example
<p id="demo"></p>
<script>
let text = "";
for (let i = 0; i < 10; i++) {
if (i === 3) { continue; } // skip 3
if (i === 6) { break; } // stop at 6
text += "The number is " + i + "<br>";
}
document.getElementById("demo").innerHTML = text;
</script>
Keep reading “JS Break”
Sign up to read the full lesson, try every example in the live editor, and take the 5-question quiz.