C++ continue Statement

Hi everyone, inside this article we will see about C++ continue Statement.

The “continue” statement in C++ is used to skip the current iteration of a loop and move on to the next iteration. When a “continue” statement is encountered inside a loop, the current iteration of the loop is terminated and the next iteration begins.

Syntax & Explanation

It is defined using the following syntax:

jump-statement;      
break;  

Here, a pictorial representation of continue statement:

A Basic Program

Here’s a simple program in C++ that demonstrates the use of a continue statement:

#include <iostream>  
using namespace std;  

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

    return 0;        
}  

The output of this program will be:

1
3
5
7
9

C++ Continue Statement with Inner Loop

C++ Continue Statement continues inner loop only if you use continue statement inside the inner loop.

A basic program for it:

#include <iostream>
using namespace std;

int main()
{
    for (int i = 1; i <= 3; i++)
    {
        for (int j = 1; j <= 3; j++)
        {
            if (i == 2 && j == 2)
            {
                continue;
            }
            cout << i << " " << j << "\n";
        }
    }
    return 0;
}

The output of this program will be:

1 1
1 2
1 3
2 1
2 3
3 1
3 2
3 3

We hope this article helped you to understand about C++ continue Statement in a very detailed way.

Online Web Tutor invites you to try Skillshike! Learn CakePHP, Laravel, CodeIgniter, Node Js, MySQL, Authentication, RESTful Web Services, etc into a depth level. Master the Coding Skills to Become an Expert in PHP Web Development. So, Search your favourite course and enroll now.

If you liked this article, then please subscribe to our YouTube Channel for PHP & it’s framework, WordPress, Node Js video tutorials. You can also find us on Twitter and Facebook.