Cplusplus-cpp-continue-statement
提供:Dev Guides
C ++ continueステートメント
*continue* ステートメントは、breakステートメントのように機能します。 ただし、強制的に終了する代わりに、continueはループの次の反復を強制的に実行し、その間のコードをスキップします。
*for* ループの場合、continueは条件付きテストを実行し、ループの増分部分を実行します。 *while* および *do ... while* ループの場合、プログラム制御は条件付きテストに渡されます。
構文
C ++のcontinueステートメントの構文は-
continue;
流れ図
例
#include <iostream>
using namespace std;
int main () {
//Local variable declaration:
int a = 10;
//do loop execution
do {
if( a == 15) {
//skip the iteration.
a = a + 1;
continue;
}
cout << "value of a: " << a << endl;
a = a + 1;
}
while( a < 20 );
return 0;
}
上記のコードをコンパイルして実行すると、次の結果が生成されます-
value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 16
value of a: 17
value of a: 18
value of a: 19