Latest web development tutorials

C ++ continue statement

C ++ loop C ++ loop

Continue statement in C ++ a bit like a breakstatement. But it is not forced to terminate, continue will skip the current code in the loop, forced to start a next cycle.

For thefor loop,continue statement causes the condition to perform the test cycles and incremental part. Forwhile and do ... whileloop, continue statement causes program control returns to the conditional test.

grammar

Continue statement in C ++ syntax:

continue;

flow chart

C ++ continue statement

Examples

#include <iostream>
using namespace std;
 
int main ()
{
   // 局部变量声明
   int a = 10;

   // do 循环执行
   do
   {
       if( a == 15)
       {
          // 跳过迭代
          a = a + 1;
          continue;
       }
       cout << "a 的值:" << a << endl;
       a = a + 1;
   }while( a < 20 );
 
   return 0;
}

When the above code is compiled and executed, it produces the following results:

a 的值: 10
a 的值: 11
a 的值: 12
a 的值: 13
a 的值: 14
a 的值: 16
a 的值: 17
a 的值: 18
a 的值: 19

C ++ loop C ++ loop