C++ Continue Statement

In C++, the continue statement is used to skip the current iteration of a loop and move to the next iteration, without executing the remaining code in the current loop iteration. It’s commonly used when you want to skip certain steps under a specific condition while keeping the loop running.

The continue statement causes the program to skip the rest of the loop in the current iteration as if the end of the statement block had been reached.

Syntax:


continue;

Note: 

1. The continue statement only affects the current iteration of the loop. The loop itself continues running until its exit condition is met.

2. It’s often used when you want to skip certain iterations of the loop but don’t want to break the loop entirely.

Where to use continue statement?

We can use in for, while, and do-while loops.

Example:


#include <iostream>
using namespace std;

int main() {
 for (int i = 1; i <= 5; i++) {
        if (i == 4) {
            continue;  // Skip the rest of the loop when i is 4
        }
        cout << i << endl;
    }
    return 0;
}

Output:

1
2
3
5

C++ Continue Statement – Interview Questions

Q 1: What does continue do?
Ans: Skips current iteration and continues loop.
Q 2: Can continue be used in switch?
Ans: No.
Q 3: Difference between break and continue?
Ans: break exits loop, continue skips iteration.
Q 4: Does continue end loop?
Ans: No.
Q 5: Can continue be used in all loops?
Ans: Yes.

C++ Continue Statement – Objective Questions (MCQs)

Q1. What is the purpose of the continue statement in C++?






Q2. What will be the output of this code?

for(int i = 1; i <= 5; i++) {
if(i == 3)
continue;
cout << i << " ";
}






Q3. In which of the following loops can the continue statement be used?






Q4. What will be the output of the following code?

int i = 0;
while(i < 5) {
i++;
if(i == 2)
continue;
cout << i << " ";
}






Q5. Which statement about continue is TRUE?






Related C++ Continue Statement Topics