In this tutorial you will learn about the C++ Continue statement and its application with practical example.
C++ Continue Statement
In C++, the continue statement gives you way to skip over the current iteration of any loop. When a continue statement is encountered in the loop, the rest of statements in the loop body for current iteration and returns the program execution to the very first statement in the loop body. It does not terminates the loop rather continues with the next iteration.
C++ Continue Statement Flow Diagram
Syntax:-
1 |
continue; |
Example:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
#include <iostream> using namespace std; int main() { int ctr = 0; cout<<"W3Adda - C++ Continue Statement"; while(ctr < 10){ ctr = ctr + 1; if(ctr == 5){ cout<<"\n5 is skipped"; continue; } cout<<"\nNumber is "<<ctr; } cout<<"\nOut of while loop"; return 0; } |
When we run the above C++ program, we will see following output –
Output:-
As you can see when ctr == 5, continue statement is executed which causes the current iteration to end and the control moves on to the next iteration.