The continue Statement
Collapse the table of content
Expand the table of content
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

The continue Statement


The continue statement forces transfer of control to the controlling expression of the smallest enclosing do, for, or while loop. Any remaining statements in the current iteration are not executed. The next iteration of the loop is determined as follows:

  • In a do or while loop, the next iteration starts by reevaluating the controlling expression of the do or while statement.
  • In a for loop (using the syntax for(init-expr; cond-expr; loop-expr)), continue causes loop-expr to be executed. Then cond-expr is reevaluated and, depending on the result, the loop either terminates or another iteration occurs.

The following example shows how the continue statement can be used to bypass sections of code and begin the next iteration of a loop:

// continue_statement.cpp
#include <stdio.h>
int main()
   int i = 0;
      printf("before the continue\n");
      printf("after the continue, should never print\n");
   } while (i < 3);

   printf("after the do loop\n");


before the continue
before the continue
before the continue
after the do loop

See Also

Jump Statements | C++ Keywords

© 2016 Microsoft