continue ステートメント (C++)

外側にある最小の dofor、または while ループの制御式に強制的に制御を移します。

構文

continue;

解説

現在のイテレーションの残りのステートメントは実行されません。 ループの次のイテレーションは、次のように決定されます。

  • do または while ループ内では、次のイテレーションは do または while ステートメントの制御式を再評価することによって開始されます。

  • 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

関連項目

ジャンプ ステートメント
キーワード