C++ continue Statement

C++ Loops

In C++continueThe statement is somewhat likebreakstatement. But it is not a forced termination; continue will skip the code in the current loop and force the start of the next loop.

forforloop,continuestatement causes the condition test and the loop increment part to be executed. Forwhileanddo...whileloop,continuestatement causes program control to return to the condition test.

Syntax

In C++continue The syntax of the statement:

continue;

Flowchart

C++ continue 语句

Example

Example

#include <iostream>
using namespace std;
 
int main ()
{
   // Local variable declaration
   int a = 10;

   // do loop execution
   do
   {
       if( a == 15)
       {
          // skip iteration
          a = a + 1;
          continue;
       }
       cout << "value of 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++ Loops

other extensions