[ JavaScript Statements Reference](#)
## Example
This example uses the break statement inside a loop.
The loop code block exits when variable i equals "3":
var text = ""
var i;
for (i = 0; i < 5; i++) {
if (i == 3) {
break;
}
text += "The number is " + i + "
";
}
_text_ output result:
The number is 0
The number is 1
The number is 2
[Try it yourself Β»](#)
More examples are included at the bottom of this article.
* * *
## Definition and Usage
The break statement is used to exit a switch statement or a loop statement (for, for ... in, while, do ... while).
When the break statement is used inside a switch statement, it exits the switch code block and terminates execution.
When the break statement is used inside a loop statement, it terminates the loop execution and proceeds to execute the code following the loop (if any).
The break statement can also be used with an optional label reference to exit a code block. (See "More Examples" below.)
**Note:** The break statement (without a label reference) can only be used inside loops or switch statements.
* * *
## Browser Support
| Statement | | | | | |
| --- | --- | --- | --- | --- | --- |
| break | Yes | Yes | Yes | Yes | Yes |
* * *
## Syntax
break;
Using an optional label reference:
break _labelname_;
## Technical Details
| JavaScript Version: | 1.0. Optional labels are supported in JavaScript 1.2. |
| --- |
* * *

## More Examples
## Example
This example uses the break statement inside a while loop.
The loop code block exits when i equals "3":
var text = "";
var i = 0;
while (i < 5) {
text += "
The number is " + i;
i++;
if (i == 3) {
break;
}
}
_text_ output result:
The number is 0
The number is 1
The number is 2
[Try it yourself Β»](#)
## Example
Exit the switch statement block to ensure only one case block executes:
var day;
switch (new Date().getDay()) {
case 0:
day = "Sunday";
break;
case 1:
day = "Monday";
break;
case 2:
day = "Tuesday";
break;
case 3:
day = "Wednesday";
break;
case 4:
day = "Thursday";
break;
case 5:
day = "Friday";
break;
case 6:
day = "Saturday";
break;
}
_day_ output result:
Sunday
[Try it yourself Β»](#)
## Example
Use the break statement with a label reference to exit a code block:
var cars = ["BMW", "Volvo", "Saab", "Ford"];
var text = "";
list: {
text += cars + "
";
text += cars + "
";
text += cars + "
";
break list;
text += cars + "
";
}
_text_ output result:
BMW
Volvo
Saab
[Try it yourself Β»](#)
## Example
Use the break statement with a label reference to exit nested loops:
var text = "";
var i, j;
Loop1: // First loop label "Loop1"
for (i = 0; i < 3; i++) {
text += "
" + "i = " + i + ", j = ";
Loop2: // Second loop label "Loop2"
for (j = 10; j < 15; j++) {
if (j == 12) {
break Loop2;
}
document.getElementById("demo").innerHTML = text += j + " ";
}
}
_text_ output result:
i = 0, j = 10 11
i = 1, j = 10 11
i = 2, j = 10 11
[Try it yourself Β»](#)
* * *
## Related Pages
JavaScript Tutorial: (#)
JavaScript Tutorial: (#)
JavaScript Tutorial: (#)
JavaScript Tutorial: (#)
JavaScript Reference: (#)
JavaScript Reference: (#)
* * JavaScript Statements Reference](#)
Jsref Break
π
2026-06-14 | π JavaScript
YouTip