Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/myscript/public_html/classes/classdb.php on line 42
Continue Statement - Skip Loop - C++ Control Structures Tutorial

Continue Statement - C++ Control Structures

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

Explanation

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.

Syntax:


continue;

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";
continue;
}
cout<<"Not Skipped"<};
cout << "Exited Loop" << '\n' ;
}

Result :

Enter a Integer::3
Value of i is:: 3
SKIPPED
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