continue statement in c++


  • The continue statement is used inside loop. When a continue statement is encountered inside a loop, control jumps to the beginning of the loop for next iteration, skipping the execution of statements inside the body of loop for the current iteration.
  • The continue statement causes an immediate jump to the top of a loop.
  • It also sometimes lets you avoid statement nesting.
  • The continue statement brings back program control to the start of the loop. You can use it for both ‘for’ and ‘while’ loops.
  • The continue statement is very similar to the break statement, except that instead of terminating the loop, it starts executing the body of the loop over from the top.

Syntax

    continue;

Flow Diagram

    continue statement in c++ language

Example

    #include <iostream>
    using namespace std;
    
       int main()
        {
         int t;
    
         for(t=0; t<100; t++)
          {
           if(t%2)
            continue;
           cout << t << ' ';
         }
      return 0;
    }
    

Output

    //Only even Numbers are printed