Continue Statement - C++ Control Structures

Using Continue Statement in C++?
How to skip current iteration of a loop?


Continue statement is used to skip the code after the "continue" and go ahead with the next iteration of a loop.

Difference between "break" and "continue":

The "break" statement terminates the current statement, but a "continue" statement terminates the current iteration of a loop by not executing statements after it.



Example :

#include <iostream.h>
void main()
int i;
cout << "Enter a integer::" << '\n';
cin >> i;
while(i >0)
cout << "Value of i is::" << i <i--;
if (i==2)
cout << "SKIPPED\n";
cout<<"Not Skipped"<};
cout << "Exited Loop" << '\n' ;

Result :

Enter a Integer::3
Value of i is:: 3
Value of i is:: 1
Not skipped
Exited Loop

In the above example only when the value of i is 2 the "cout" statement with message "skipped" is executed, and the "cout" statement with the message is skipped.

C++ Tutorial

Ask Questions

Ask Question