Core JavaScript 1.5 Reference:Statements:break
From MDC
Contents |
[edit] Summary
Terminates the current loop, switch, or label statement and transfers program control to the statement following the terminated statement.
| Statement | |
| Implemented in: | JavaScript 1.0, NES 2.0 |
| ECMA Version: | ECMA-262 (for the unlabeled version)
ECMA-262, Edition 3 (for the labeled version) |
[edit] Syntax
break [label];
[edit] Parameters
-
label - Identifier associated with the label of the statement.
[edit] Description
The break statement includes an optional label that allows the program to break out of a labeled statement. The break statement needs to be nested within this labelled statement. The labelled statement can be any type of statement; it does not have to be a loop statement.
[edit] Examples
[edit] Example: Using break
The following function has a break statement that terminates the while loop when i is 3, and then returns the value 3 * x.
function testBreak(x) {
var i = 0;
while (i < 6) {
if (i == 3) {
break;
}
i += 1;
}
return i * x;
}