JavaScript » Statements » continue

Syntax:
continue [label]

The continue statement is used to restart a while, do...while, for or label statement. In a while loop it jumps back to the condition.

Examples

Code:
var i = 0  
while (i < 10)
{
   i++;
   if (i==7)
      continue;
   document.write(i + ".<BR>");
}
Explanation:

In this example the code produces the numbers 1 thru 10 but skips the number 7.

Code:
for(i=0; i<4; i++)
{
   if (i==2)
      continue;
   document.write(drink[i]);
}
Explanation:

...while in a for loop it jumps back to the update expression, as in this example which lists all the elements of the array 'drink' except for when the array index equals 2 (Note: since the array indexing starts at zero, index 2 is the 3rd element in the array).

Code:
count_loop:
for(i=0; i<3; i++)
{
   document.write("<BR>" + "outer " + i + ":   ");
   for(j=0; j<10; j++)
   {
      document.write("inner " + j + " ");
      if(j==i+3)
         continue count_loop;
   }
}
Explanation:

It can also be used with a label as in this example which displays an outer and inner count, but limits the inner count to 3 more than the outer.