javascript icon

Break & Continue

Expert Answer & Key Takeaways

A complete guide to understanding and implementing Break & Continue.

JavaScript Break and Continue

The break and continue statements are used to jump out of a loop or skip an iteration in a loop. They provide precise control over the execution flow inside repetitive blocks.

1. The Break Statement

You have already seen the break statement used in the switch statement. It can also be used to jump out of a loop.
for (let i = 0; i < 10; i++) { if (i === 3) { break; } text += "The number is " + i + "<br>"; }
In the example above, the loop will stop completely when i reaches 3.

2. The Continue Statement

The continue statement breaks one iteration (in the loop), if a specified condition occurs, and continues with the next iteration in the loop.
for (let i = 0; i < 10; i++) { if (i === 3) { continue; } text += "The number is " + i + "<br>"; }
In the example above, the loop will skip the number 3, but then continue with the rest of the loop (4, 5, 6...).

3. JavaScript Labels

To label a JavaScript statement, you precede the statements with a label name and a colon. You can use break and continue with labels to jump out of or skip code blocks that are not just the immediate parent loop.
outerLoop: for (let i = 0; i < 3; i++) { for (let j = 0; j < 3; j++) { if (i === 1 && j === 1) { break outerLoop; } console.log(`i=<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>i</mi><mo separator="true">,</mo><mi>j</mi><mo>=</mo></mrow><annotation encoding="application/x-tex">{i}, j=</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.854em;vertical-align:-0.1944em;"></span><span class="mord"><span class="mord mathnormal">i</span></span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathnormal" style="margin-right:0.05724em;">j</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span></span></span></span>{j}`); } }
[!IMPORTANT] Labels are rarely used in modern 2026 JavaScript code, but they are a common "gotcha" question in senior-level technical interviews.

Top Interview Questions

?Interview Question

Q:What is the difference between break and continue?
A:
The 'break' statement exits the entire loop immediately. The 'continue' statement only skips the current iteration and jumps to the next one in the same loop.

?Interview Question

Q:Can you use 'break' outside of a loop or switch?
A:
No, a 'break' statement without a label can only be used inside a loop or a switch statement. Using it elsewhere will throw a SyntaxError.

?Interview Question

Q:What are labels in JavaScript loops?
A:
Labels are names followed by a colon (identifier:) that can be placed before a loop. They allow you to use break or continue to target a specific parent loop in nested scenarios.

Course4All Editorial Board

Verified Expert

Senior Full-Stack Engineers & V8 Experts

Our JavaScript and engine-level content is developed by a collective of senior engineers focused on high-performance web architecture and 2026 standards.

Pattern: 2026 Ready
Updated: Weekly