Continue to a label in JavaScript

Description

The following code shows how to continue to a label.

Example


<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">
outerLoop:<!--from   w  w  w  . jav  a2  s  .c om-->
for (var i1 = 1; i1 <= 2; i1++)
{
document.write("Top of outerLoop.<BR>");
innerLoop:
for (var i2 = 1; i2 <= 2; i2++) {
document.write("Top of innerLoop.<BR>");
document.write("i1=",i1,"<BR>");
document.write("i2=",i2,"<BR>");
if (i2 == 2)
{
document.write("Continue at top of innerLoop.<BR>");
continue;
}
if (i1 == 2)
{
document.write("Continue at top of outerLoop.<BR>");
continue outerLoop;
}
document.write("Bottom of innerLoop.<BR>");
}
document.write("Bottom of outerLoop.<BR>");
}
document.write("All done!");
</script>
</body>
</html>

Click to view the demo

The code above generates the following result.

Continue to a label in JavaScript
Home »
  Javascript Tutorial »
    Statement »
      Break Continue
Javascript Tutorial Break Continue
Break out of a while statement in JavaScrip...
Break to a label in JavaScript
Continue a while loop in JavaScript
Continue statement in a if statement in Jav...
Continue to a label in JavaScript
Put Break statement in a if statement in Ja...
Use Mod operator to check even number in Ja...
Use break statement to jump to outer loop i...
Use continue statement to jump to outer mos...