Core JavaScript 1.5 Guide:Loop Statements:break Statement
From MDC
[edit] break Statement
Use the break statement to terminate a loop, switch, or label statement.
- When you use
breakwithout a label, it terminates the innermost enclosingwhile, do-while, for,orswitchimmediately and transfers control to the following statement. - When you use
breakwith a label, it terminates the specified labeled statement.
The syntax of the break statement looks like this:
-
break; -
break label;
The first form of the syntax terminates the innermost enclosing loop or switch; the second form of the syntax terminates the specified enclosing label statement.
Example
The following example iterates through the elements in an array until it finds the index of an element whose value is theValue:
for (i = 0; i < a.length; i++) {
if (a[i] == theValue)
break;
}