continue statement in c++ program

The continue statement is used to stop the current iteration of a loop and jump to the next iteration. It is typically used within a loop to skip the remaining code in the current iteration and proceed to the next iteration.

When the continue statement is encountered, the program will ignore the rest of the statements in the loop's body for the current iteration, and the loop will immediately move to the next iteration.

Here's an example of how the continue statement works in a loop:

#include <iostream>
using namespace std;

int main() {
   for (int i = 1; i <= 5; i++) {
      if (i == 3) {
         continue; // Skips the remaining code for i=3 and moves to the next iteration
      }
      cout << "The value of i is: " << i << endl;
   }
   return 0;
}

In this example, when the value of i is 3, the continue statement is encountered, and the rest of the code inside the loop is skipped for that iteration. As a result, the output will be:

The value of i is: 1
The value of i is: 2
The value of i is: 4
The value of i is: 5