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.
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
Prev | Home | Next |
Braces { } | Up | Broken-down time |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |