[Contents] [Previous] [Next] [Index]

continue

Terminates execution of the block of statements in a while or for loop, and continues execution of the loop with the next iteration.

Implemented in

Navigator 2.0, LiveWire 1.0

Syntax

continue
continue label

Argument

label
Identifier associated with the label of the statement.

Description

In contrast to the break statement, continue does not terminate the execution of the loop entirely: instead,

The continue statement can now include an optional label that allows the program to terminate execution of a labeled statement and continue to the specified labeled statement. This type of continue must be in a looping statement identified by the label used by continue.

Examples

The following example shows a while loop that has a continue statement that executes when the value of i is 3. Thus, n takes on the values 1, 3, 7, and 12.

i = 0
n = 0
while (i < 5) {
   i++
   if (i == 3)
      continue
   n += i
}
In the following example, a statement labeled checkiandj contains a statement labeled checkj. If continue is encountered, the program continues at the top of the checkj statement. Each time continue is encountered, checkj reiterates until its condition returns false. When false is returned, the remainder of the checkiandj statement is completed. checkiandj reiterates until its condition returns false. When false is returned, the program continues at the statement following checkiandj.

If continue had a label of checkiandj, the program would continue at the top of the checkiandj statement.

checkiandj : 
while (i<4) {
   document.write(i + "<BR>");
   i+=1;
   checkj : 
   while (j>4) {
      document.write(j + "<BR>");
      j-=1;
      if ((j%2)==0)
         continue checkj;
      document.write(j + " is odd.<BR>");
   }
   document.write("i = " + i + "<br>");
   document.write("j = " + j + "<br>");
}

See also

labeled


[Contents] [Previous] [Next] [Index]

Last Updated: 10/31/97 12:29:59


Copyright � 1997 Netscape Communications Corporation