The continue keyword is a jump statement. It is used in an iterator loop to proceed to the next cycle without executing the remaining lines in the statement block.
A continue 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 continue statement.
The continue statement would normally be executed conditionally, otherwise it would cause the remaining lines to be redundant since no execution flow would ever reach them. Compilers generally warn you about this, but JavaScript would likely simply ignore it.
The continue statement is obeyed by the smallest enclosing iterator loop.
At version 1.2 of JavaScript, the continue statement was enhanced to support a label as a continuing destination. When the continue is processed, it will jump to the start of the statement that has been labeled. If an iterator is labeled, then the continue is associated with that iterator. This mechanism can only be used in a while, for or for ... in loop.
A labeled continue behaves differently according to the iterator it has been used in.
In Netscape 4, there is a bug with labeled continue statements and do ... while loops that causes the continue to vector to the top of the loop without testing the condition. This can set up an endless loop. You could work round this by creating a while loop and modifying the test condition.
When the continue statement is used, its behavior inside a while loop suggests that a while loop is not exactly similar to a for loop. In a while loop, it simply runs the test condition again before deciding to loop or not. In a for loop, the incrementor gets executed again and then the test condition. You cannot perfectly simulate a for loop with a while loop if a continue statement is involved.
ECMA 262 edition 2 - section - 10.1.4
ECMA 262 edition 2 - section - 12.7
ECMA 262 edition 3 - section - 10.1.4
ECMA 262 edition 3 - section - 12.7
Wrox Instant JavaScript - page - 25
Prev | Home | Next |
contextual() | Up | Control character |
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. |