continue Statement


  • It may be necessary to skip a part of the body of the loop. That is, when loop is in execution, on certain condition the rest of the execution of the loop concerned is to be ignored and the loop should continue for the next iteration. The control statement called continue is used to achieve this. This statement causes the loop to be continued, with the next iteration after updating the control variable, without executing the rest of the statements in the loop. It applies to the loop immediately enclosing the continue statement. It is an error to use the continue statement outside a loop.
  • When the continue statement appears inside nested loops, it applies to the loop immediately enclosing it, and not to the outer loops.
    Example:
    for (i=1; i<=5; i++)
    {
    if (i==3)
     		continue;
        cout << i;
    }
        For the above example, only =1, 2, 4, 5 will be printed. When i is equal to 3, control is returned to the beginning of the loop.
    
    Example


Looping Structure << Previous

Next >> Break Statement

Our aim is to provide information to the knowledge seekers. 

comments powered by Disqus


Footer1