STATEMENT:
continue
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.
In the following example the
code produces the numbers 1 thru 10 but skips the number 7:
Code:
var i = 0
while (i < 10)
{
i++;
if (i==7)
continue;
document.write(i + ".<BR>");
}
...while in a for loop it jumps back to the update expression,
as in the next example which lists all the elements of the array 'drink'
except for the second:
Code:
for(i=0; i<4; i++)
{
if (i==2)
continue;
document.write(drink[i]);
}
It can also be used with a label as in the next example which displays
an outer and inner count, but limits the inner count to 3 more than the
outer:
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;
}
}
|