continue in C++

The C++ continue statement is used to execute other parts of the loop while skipping some parts declared inside the condition, rather than terminating the loop, it continues to execute the next iteration of the same loop. It is used with a decision-making statement which must be present inside the loop.

This statement can be used inside for loop or while or do-while loop.

Syntax of continue

continue;

Flowchart of continue Statement

Example of continue Statement

Consider a scenario where all the numbers between 1 and 10 except number 5. So in this case, the idea is to use the continue statement after the value of i is 5. Below is the program for the same:

C++




// C++ program to demonstrate the
// continue statement
#include <iostream>
using namespace std;
 
// Driver code
int main()
{
    for (int i = 1; i < 10; i++) {
 
        if (i == 5)
            continue;
        cout << i << " ";
    }
    return 0;
}


Output

1 2 3 4 6 7 8 9 

Jump statements in C++

Jump statements are used to manipulate the flow of the program if some conditions are met. It is used to terminate or continue the loop inside a program or to stop the execution of a function.

Similar Reads

Types of Jump Statements in C++

In C++,  there is four jump statement...

continue in C++

The C++ continue statement is used to execute other parts of the loop while skipping some parts declared inside the condition, rather than terminating the loop, it continues to execute the next iteration of the same loop. It is used with a decision-making statement which must be present inside the loop....

break in C++

...

return in C++

The C++ break statement is used to terminate the whole loop if the condition is met. Unlike the continue statement after the condition is met, it breaks the loop and the remaining part of the loop is not executed....

Goto statement in C++

...