©
Ce document utiliseManuel du site Web PHP chinoisLibérer
导致封闭的剩余部分 for,while 或 do-while 循环体被跳过。
当使用条件语句忽略循环的剩余部分时,使用它时很尴尬。
continue ; |
|
|
---|
continue
语句会像跳转一样跳转到循环体的末尾(它可能只出现在for,while 和 do-while 循环的循环体内)。
对于 while 循环,它充当。
while (/* ... */) { // ... continue; // acts as goto contin; // ... contin:;}
对于 do-while 循环,它的作用如下:
do { // ... continue; // acts as goto contin; // ... contin:;} while (/* ... */);
对于 for 循环,它的作用是:
for (/* ... */) { // ... continue; // acts as goto contin; // ... contin:;}
continue
.
#includeint main(void) { for (int i = 0; i < 10; i++) { if (i != 5) continue; printf("%d ", i); //this statement is skipped each time i!=5 } printf("\n"); for (int j = 0; j < 2; j++) { for (int k = 0; k < 5; k++) { //only this loop is affected by continue if (k == 3) continue; printf("%d%d ", j, k); //this statement is skipped each time k==3 } }}
输出:
500 01 02 04 10 11 12 14
C11 standard (ISO/IEC 9899:2011):
6.8.6.2 The continue statement (p: 153)
C99 standard (ISO/IEC 9899:1999):
6.8.6.2 The continue statement (p: 138)
C89/C90 standard (ISO/IEC 9899:1990):
3.6.6.2 The continue statement