C++ continue statement

« Previous Chapter Next Chapter »

The continue statement works somewhat like the break statement. Instead of forcing termination, however, continue forces the next iteration of the loop to take place, skipping any code in between.

For the for loop, continue causes the conditional test and increment portions of the loop to execute. For the while and do...while loops, program control passes to the conditional tests.

Syntax:

The syntax of a continue statement in C++ is:

Example

continue;
                                        

Flow Diagram:

Example:

Example

#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;
}
                                        

When the above code is compiled and executed, Output Will Be :

Example

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
                                        


« Previous Chapter Next Chapter »

Have Any Suggestion? We Are Waiting To Hear from YOU!

Your Query was successfully sent!