Continue statement in C++: Difference between break and continue statement

Continue statement in C++: Difference between break and continue statement

26 Jul 2025
Beginner
4.26K Views
13 min read
Learn with an interactive course and practical hands-on labs

Free C++ Online Course With Certificate

Continue Statement in C++: An Overview

In this C++ tutorial on jump statements, we will now look at the continue statement in C++ in detail. We saw that the break statement is used to prematurely exit from the loop or switch case. The continue statement works a little differently than the break statement. For a more in-depth understanding, consider our Free C++ Course With Certificate program.

What is the Continue Statement in C++?

The continue statement is used to skip the current iteration of any loop and bring the control to the beginning of the iteration. The statements following the continue statement are skipped and the iteration starts again.

What is the Continue Statement in C++?

Syntax

//loop statements 
continue; 
//some lines of the code which is to be skipped

We will now see the continue statement with the for loop, while loop, do...while loop, and nested loop in C++. If you are weak in the concepts of loops and conditional statements, go back and refer to the tutorials on conditional statements in C++ and loops in C++ programming.

Read More - C++ Interview Interview Questions and Answers

Continue Statement with for loop in C++

In a for loop, the continue statement skips the current iteration and the control goes to the update expression.

Example to demonstrate continue statement with for loop in C++ Compiler

#include <iostream>
using namespace std;
int main() {
 for (int i = 1; i <= 10; i++) {
 if (i == 5) {
 continue;
 }
 cout << i << endl;
 }
 return 0;
}
  • This C++ program iterates 10 times using a for loop.
  • The continue statement is encountered when i=5. So it skips the remainder of the loop's body for that iteration.
  • As a result, it only prints the numbers 1-4 and 6-10, skipping 5.

Output

1
2
3
4
6
7
8
9
10

Continue Statement with while loop in C++

In a while loop, the continue statement skips the current iteration and the control goes back to the while condition.

Example to demonstrate continue statement with while loop in C++

#include <iostream>
using namespace std; 
 
int main() 
{ 
 int i = 0; 
 while (i < 10) { 
 i++; 
 if (i == 5) { 
 continue; //the iteration is skipped
 } 
 else { 
 // prints the value of i 
 cout << i << " "; 
 } 
 } 
 return 0; 
}
  • The above program prints the numbers from 1 to 10 using a while loop in C++
  • When i becomes 5, the continue statement is encountered. Therefore the iteration at i=5 is skipped
  • The iteration again starts with i=6 and prints the value from 1 to 10 skipping 5.

Output

1 
2 
3 
4
6 
7 
8 
9 
10 

Continue Statement with do...while loop in C++

When a continue statement is encountered in the do...while loop, the control jumps directly to the update expression, and the remaining code in the loop body gets skipped.

Example to demonstrate continue statement with do...while loop in C++

 #include <iostream>
using namespace std; 
 
int main() 
{ 
 int i = 0; 
 do { 
 i++; 
 if (i == 3) { 
 continue; //skips the iteration
 } 
 else { 
 // prints the value of i 
 cout << i << endl; 
 } 
 
 } while (i < 10); 
 return 0; 
}
  • The above program uses the do...while loop in C++ to print the numbers from 1 to 10.
  • When i=3, the iteration is skipped and the control goes to the update expression i++.
  • The value of i increments and the output gets printed from 1 to 10 except 3.

Output

1
2
4
5
6
7
8
9
10

Continue Statement with a nested loop in C++

When the continue statement is used with nested loops in C++, it skips the current iteration of the inner loop.

Example to demonstrate continue statement with a nested loop in C++ Online Editor

#include <iostream>
using namespace std; 
 
int main() 
{ 
 
 for (int i = 1; i <= 3; i++) { 
 for (int j = 0; j <= 5; j++) { 
 if (j == 3) { 
 continue; 
 } 
 cout << j << " "; 
 } 
 cout << endl; 
 } 
 
 return 0; 
}
  • The above C++ program uses a nested loop to print numbers from 1 to 5 in three rows.
  • The outer loop i runs for three times.
  • In each ith iteration, the inner loop j prints numbers from 1 to 5.
  • In the inner loop when j=3, the iteration is skipped and 3 does not get printed due to the continue statement.
  • We get three rows of numbers from 1 to 5 except 3 in each row.

Output

1 2 4 5 
1 2 4 5 
1 2 4 5 

Comparison of Break and Continue Statements in C++

Parametersbreak statement in C ++continue statement in C++
PurposeExits the current loopSkips the current iteration
ApplicabilityUsed within loops (for, while, do-while)Used within loops (for, while, do-while)
EffectTerminates the loop prematurely and continues with the next statement after the loopImmediately moves to the next iteration of the loop, skipping the remaining code in the current iteration
Loop ControlAffects the entire loopAffects only the current iteration of the loop
Typical Use CasesWhen a specific condition is met, and you want to exit the loopWhen you want to skip the current iteration of the loop based on a certain condition and continue with the next iteration
Summary
We saw how the continue statement skips the current iteration and behaves accordingly in all four loops. We even saw the comparison in the behavior of break and continue statements in C++. For hands-on and practical understanding, consider our C++ Certification Course.
Share Article
About Author
Shailendra Chauhan (Microsoft MVP, Founder & CEO at ScholarHat)

He is a renowned Speaker, Solution Architect, Mentor, and 10-time Microsoft MVP (2016–2025). With expertise in AI/ML, GenAI, System Design, Azure Cloud, .NET, Angular, React, Node.js, Microservices, DevOps, and Cross-Platform Mobile App Development, he bridges traditional frameworks with next-gen innovations.

He has trained 1 Lakh+ professionals across the globe, authored 45+ bestselling eBooks and 1000+ technical articles, and mentored 20+ free courses. As a corporate trainer for leading MNCs like IBM, Cognizant, and Dell, Shailendra continues to deliver world-class learning experiences through technology & AI.
Live Training - Book Free Demo
Azure AI Engineer Certification Training
20 Sep
07:00AM - 09:00AM IST
Checkmark Icon
Get Job-Ready
Certification
Azure AI & Gen AI Engineer Certification Training Program
20 Sep
07:00AM - 09:00AM IST
Checkmark Icon
Get Job-Ready
Certification
Advanced Full-Stack .NET Developer with Gen AI Certification Training
21 Sep
07:00AM - 09:00AM IST
Checkmark Icon
Get Job-Ready
Certification
ASP.NET Core Certification Training
21 Sep
07:00AM - 09:00AM IST
Checkmark Icon
Get Job-Ready
Certification
Azure DevOps Certification Training
24 Sep
08:30PM - 10:30PM IST
Checkmark Icon
Get Job-Ready
Certification
Accept cookies & close this