Continue Statement in C++

Hello learners, so are you curious about knowing the continue Statement in c++? If yes, then this article is all about the continue statement. If you already know C++, you can directly switch here.

The continue statement used in various programming languages, is a loop control statement used within the loop.

C++ uses the “continue” keyword, to implement the continue statement, which transfers the flow of the program at the start of the loop and skips the current statement when it is encountered.

The continue statement forces the loop to continue or execute the next iteration rather than terminating the loop (break statement). When the continue statement is implemented within the loop, the code following the continue statement is skipped, and the control flow will move to the next iteration of the loop.

Related: Best IDE for C++ programming

Syntax

continue;

Working of Continue Statement in C++

  • Save
Flow control for continue statement in C++

Whenever we encounter continue statement, the control immediately skips to the next iteration. Let’s look at some illustrations which are given below to better understand the working of continue statement.

Related: Most exhaustive list for star pattern problems in C++

Example

The following C++ program will demonstrate how to use the continue statement in a “for loop”.

#include <iostream>

using namespace std;

int main(){

    for(int i=1;i<=3;i++){

        if(i == 2){
            continue;
        }

        cout<<i<<endl;

    }
}

Output

1
3

Explanation

We used the for loop method in the preceding program to demonstrate the implementation of the continue statement. Here, if variable i = 2, then the program encounters, continue statement, which immediately transfer the control to the next statement, ignoring the code below it. That’s why it ignored “cout<<i”.

So, this was all about continue statement. Continue statement works the same way in C programming language also. Before moving to the next tutorial, he highly recommend you to practice it 2-3 times. It’ll not take much time. You can practice here.

We hope that you find the article useful, if yes then don’t forget to share it with your friends. The next tutorial will be out soon. Till then, stay tuned.

Share via
Copy link
Powered by Social Snap