What the continue statement does?

label Computer Science
account_circle Unassigned
schedule 1 Day
account_balance_wallet $5

in C++

Nov 19th, 2014

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)), the loop-expr clause is executed. Then the cond-expr clause 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

Nov 19th, 2014

Studypool's Notebank makes it easy to buy and sell old notes, study guides, reviews, etc.
Click to visit
The Notebank
...
Nov 19th, 2014
...
Nov 19th, 2014
Jun 24th, 2017
check_circle
Mark as Final Answer
check_circle
Unmark as Final Answer
check_circle
Final Answer

Secure Information

Content will be erased after question is completed.

check_circle
Final Answer