JavaScript手册
|
【目录】 【上一页】 【下一页】 【索引】
continue
Terminates execution of the block of statements in a while or for loop, and continues execution of the loop with the next iteration.
语法
continue continue label
Argument
描述
In contrast to the break statement, continue does not terminate the execution of the loop entirely: instead,
- In a while loop, it jumps back to the condition.
- In a for loop, it jumps to the update expression.
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.
示例
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>"); }
参看
labeled
【目录】 【上一页】 【下一页】 【索引】
|