continue ステートメント (C++)
外側にある最小の do、for、または 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
関連項目
フィードバック
https://aka.ms/ContentUserFeedback」を参照してください。
以下は間もなく提供いたします。2024 年を通じて、コンテンツのフィードバック メカニズムとして GitHub の issue を段階的に廃止し、新しいフィードバック システムに置き換えます。 詳細については、「フィードバックの送信と表示