Changes

Jump to: navigation, search

JavaScript Flow Control and Looping

4 bytes added, 17:49, 26 May 2007
label Statements
=== label Statements ===
One problme problem that can arise using the ''break'' statement involves breaking from a loop that is nested inside another loop. In the following example the ''break'' will break out of the inner loop, but not the outer loop:
<pre>
</pre>
In the above example the break will break out of the inner loop when x is equal to 10 but the outer ''for '' loop will continue to run. This is fine if that is the desired behavior, but is a problem if the outer loop needs to also be broken at this point. This problem can be resolved using ''label statements''. ''label statements'' are placed before the control structure and referenced in the break statement to instruct the loop to break out of all layers of nesting in the loop:
<pre>

Navigation menu