?
This document uses PHP Chinese website manual Release
導(dǎo)致封閉的剩余部分 for,while 或 do-while 循環(huán)體被跳過。
當(dāng)使用條件語句忽略循環(huán)的剩余部分時(shí),使用它時(shí)很尷尬。
continue ; |
---|
continue
語句會(huì)像跳轉(zhuǎn)一樣跳轉(zhuǎn)到循環(huán)體的末尾(它可能只出現(xiàn)在for,while 和 do-while 循環(huán)的循環(huán)體內(nèi))。
對于 while 循環(huán),它充當(dāng)。
while (/* ... */) { // ... continue; // acts as goto contin; // ... contin:;}
對于 do-while 循環(huán),它的作用如下:
do { // ... continue; // acts as goto contin; // ... contin:;} while (/* ... */);
對于 for 循環(huán),它的作用是:
for (/* ... */) { // ... continue; // acts as goto contin; // ... contin:;}
continue
.
#include <stdio.h> int 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