continue 陳述式 (C++)

強制將控制權傳送至最小封入 do for while 迴圈的控制運算式。

語法

continue;

備註

目前反覆項目中其餘的任何陳述式都不會執行。 迴圈中下一個反覆項目的判斷方式如下:

  • do在 或 while 迴圈中,下一個反復專案會從重新評估 或 while 語句的控制 do 運算式開始。

  • for在迴圈中(使用 語法 for( <init-expr> ; <cond-expr> ; <loop-expr> ) ),會 <loop-expr> 執行 子句。 然後會重新求出 <cond-expr> 子句的值,而根據結果,迴圈會結束或另一個反覆項目會發生。

下列範例示範如何使用 continue 語句略過程式碼區段,並開始迴圈的下一個反復專案。

範例

// continue_statement.cpp
#include <stdio.h>
int main()
{
    int i = 0;
    do
    {
        i++;
        printf_s("before the continue\n");
        continue;
        printf("after the continue, should never print\n");
     } while (i < 3);

     printf_s("after the do loop\n");
}
before the continue
before the continue
before the continue
after the do loop

另請參閱

跳躍陳述式
關鍵字