C++ continue statement

About C++ continue statement:

 On this page we will discuss about continue statement which is used in C++.
The continue statement is used to skip the remaining statements in the current iteration of a loop and immediately start the next iteration. It can be used to skip certain statements in a loop and continue with the next iteration.

continue statement in C++

What is C++ continue statement ?

In C++ language, the continue statement works by skipping the remaining statements in the current iteration of a loop and immediately starting the next iteration. When the continue statement is encountered, the program skips the remaining statements in the loop body and goes back to the top of the loop to evaluate the loop condition and decide whether to continue with the next iteration.

Syntax:

continue;
The continue statement is used in C++ for the following purposes:
  • The continue statement can be used to skip certain statements in a loop and continue with the next iteration.
  • This statement can also be used to skip certain iterations in a loop based on some condition.
  • It can also be used to skip certain iterations in a nested loop.

Flowchart:

continue statement in C++ flowchart

Example 1:

Run
#include <iostream> 
using namespace std;

int main()
{
   for (int i = 0; i < 10; i++) {
     if (i % 2 == 0) {
      continue;
  }
   std::cout << i << std::endl;
}

    return 0;
}

Output:

1
3
5
7
9

Example 2:

Run
#include<iostream>
using namespace std;
int main()
{
   for (int i = 0; i < 3; i++) { // first loop
     for (int j = 0; j < 3; j++) { // second loop
       if (i == 2 && j == 2) {
          continue;
    }
    std::cout << i << " " << j << std::endl;
  }
}
    return 0;
}

Output:

0 0
0 1
0 2
1 0
1 1
1 2
2 0
2 1

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription