continue Statement in C++

Last Updated : 7 Jan, 2026

C++ continue statement is a loop control statement that forces the program control to execute the next iteration of the loop. As a result, the code inside the loop following the continue statement will be skipped and the next iteration of the loop will begin.

Syntax:

continue;

java_
Loop control using the continue statement.

Continue Statement with for Loop

If continue is used in a for loop, the control flow jumps to the test expression after skipping the current iteration.

c_
Use of the continue statement inside a for loop.

Example:

C++
#include <iostream>
using namespace std;

int main(){
    for (int i = 1; i <= 10; i++) {
        if (i == 4)
            continue;
        else
            cout << i << " ";
    }
    return 0;
}

Output
1 2 3 5 6 7 8 9 10 

Explanation:

  • for (int i = 1; i <= 10; i++): runs from 1 to 10.
  • When i == 4, the continue statement skips the remaining code in the loop for that iteration.
  • Because of continue, cout << i is not executed for i = 4.
  • All other values of i are printed using cout << i << " ".

Continue Statement with While Loop

With continue, the current iteration of the loop is skipped, and control flow resumes in the next iteration of while loop.

1
Use of the continue statement inside a while loop.

Example:

C++
#include <iostream>
using namespace std;

int main(){
    int i = 0;
    while (i < 10) {
          i++;
        if (i == 4) {
            continue;
        }
        else {
            cout << i << " ";
        }
    }
    return 0;
}

Output
1 2 3 5 6 7 8 9 10 

Continue Statement with do-while Loop

In do-while loop, the condition is checked after executing the loop body. When a continue statement is encountered in the do-while loop, the control jumps directly to the condition checking for the next loop, and the remaining code in the loop body is skipped.

25592883
Use of the continue statement inside a do-while loop.

Example:

C++
#include <iostream>
using namespace std;

int main(){
    int i = 0;
    do {
        i++;
        if (i == 4) {
            continue;
        }
        else {
            cout << i << ' ';
        }

    } while (i < 10);
    return 0;
}

Output
1 2 3 5 6 7 8 9 10 

Explanation: Here, 4 is not printed as a continue statement is encountered in the case of i = 4.

Note: In while and do-while loop, we updated the loop variable i before the continue statement or else we will keep encountering continue before updating the loop variable creating an infinite loop.

Continue Statement with Nested Loops

Using continue, you skip the current iteration of the inner loop when using nested loops. 

C++
#include <iostream>
using namespace std;

int main(){
    for (int i = 1; i <= 2; i++) {
        for (int j = 0; j <= 4; j++) {
            if (j == 2) {
                continue;
            }
            cout << j << " ";
        }
        cout << endl;
    }
    return 0;
}

Output
0 1 3 4 
0 1 3 4 

Explanation: Continue skips the current iteration of the inner loop when it executes in the above program. As a result, the program is controlled by the inner loop update expression. In this way, 2 is never displayed in the output.

Continue vs Break

There are some differences between the continue and break statements which alter the normal flow of a program. 

ContinueBreak
Only the current loop iteration is stopped by a Continue statement.The break statement stops the loop in its entirety.
With Continue, subsequent iterations continue without interruption.The remaining iterations are also terminated by Break.
Continue statement can be used with for loop but it cannot be used with switch statementsThe break statement can be used with the switch statement
When you use the continue statement, and the control statements, the control remains inside the loop.When you use a break statement, the control exits from the loop.
The continue statement skips a particular loop iteration.The execution of the loop at a specific condition is stopped with a break statement.
Comment