Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
The latest version of this topic can be found at continue Statement (C++).
Forces transfer of control to the controlling expression of the smallest enclosing do, for, or while loop.
Syntax
continue;
Remarks
Any remaining statements in the current iteration are not executed. The next iteration of the loop is determined as follows:
In a
doorwhileloop, the next iteration starts by reevaluating the controlling expression of thedoorwhilestatement.In a
forloop (using the syntaxfor(init-expr;cond-expr;loop-expr)), theloop-exprclause is executed. Then thecond-exprclause is reevaluated and, depending on the result, the loop either ends 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.
Example
// continue_statement.cpp
#include <stdio.h>
int main()
{
int i = 0;
do
{
i++;
printf_s("before the continue\n");
continue;
printf("after the continue, should never print\n");
} while (i < 3);
printf_s("after the do loop\n");
}
before the continue
before the continue
before the continue
after the do loop