Continue Statement

In C++, the continue statement is used inside loops. When a continue statement is met within the loop, the control returns to the beginning of the loop for the next iteration, bypassing the execution of statements within the loop’s body following the continue statement.

It is used to transfer control to the following loop iteration. The continue statement typically bypasses some code within the loop and allows the programme to proceed to the next iteration. It is primarily used for a condition, allowing us to skip some lines of code for a specific circumstance.

In contrast to a break statement, which ends the loop the instant it is met, it forces the next iteration to follow in the loop.

Here is an illustration of how a continue statement works.

#include <iostream>
using namespace std;
 
int main()
{
    for (int i = 0; i <= 10; i++)
    {
        if (i < 6)
        {
            continue;
        }
        cout << i << " ";
    }
    return 0;
}

Output:

6 7 8 9 10

The continue statement was running indefinitely while I remained less than 5. We were able to get the print statement to function for all other values of i.

Shubhajna Rai
Shubhajna Rai

A Civil Engineering Graduate interested to share valuable information with the aspirants.

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the latest updates on your inbox

Be the first to receive the latest updates from Codesdoc by signing up to our email subscription.

    StudentProjects.in