break (Statement)

Exit unconditionally from a loop or switch.


ECMAScript edition - 2
JavaScript - 1.1
JScript - 1.0
Internet Explorer - 3.02
Netscape - 3.0
Netscape Enterprise Server - 2.0
Opera - 3.0
JavaScript syntax:-break aLabelName;
Argument list:aLabelNameThe name of a label associated with some code

The break keyword is a 'jump' statement. It is used in an loop to abort the current cycle and exit from the smallest enclosing loop immediately. Execution continues at the line following the statement block associated with the loop.

A break statement can only legally exist inside a while or for loop in an ECMA-compliant implementation. Implementations that provide additional iterator types may also honor the same behavior for the break statement.

The break statement would normally be executed conditionally, otherwise it would cause the remaining lines in the loop to be redundant, since no execution flow would ever reach them. Compilers generally warn you about this, but JavaScript would simply ignore it.

At version 1.2 of JavaScript, the break statement was enhanced to support a label as a breaking destination. When the break is processed, it will jump to the end of the statement that has been labeled. If an iterator is labeled, then the break is associated with that iterator. This mechanism works like a 'goto'. It can work with an if block and with a labeled block of brace delimited code.

See also:Completion type, continue, for( ... ) ..., for( ... in ... ) ..., Iteration statement, Jump statement, Label, return, Scope chain, Statement, switch( ... ) ... case: ... default: ..., while( ... ) ...


ECMA 262 edition 2 - section - 10.1.4

ECMA 262 edition 2 - section - 12.8

ECMA 262 edition 3 - section - 10.1.4

ECMA 262 edition 3 - section - 12.8

Wrox Instant JavaScript - page - 25