What Continue Statement In C++

The continue statement can be used in loops and has the opposite effect to break,
that is, the next loop is begun immediately.In the case of a while or do-while loop the program jumps to the test expression, whereas a for loop is reinitialized.

Example: 

for( int i = 0; i < 100; i++ ) { 

. . . // Processes all integers. 

if( i % 2 == 1)

 continue; 

. . . // Process even // numbers only. }

If we want to skip some statement in the loop then we can use there continue statement. It mostly used when we want to skip the rest of the statement in the current loop and start from the top again.

The continue statement is very similar to the break statement, except that instead of
terminating the loop, it starts executing the body of the loop over from the top. For example, if you modify the previous program to total only numbers larger than 0.

Simple example of continue statement in c++

#include<iostream>
using namespace std;
int main(){
int i=1;
clrscr();
for(i=1;i<=5;i++)
{
if(i==4)
{
continue;
}
cout<<“Welcome %dn”,i;
}
cout<<“Exit from loop here”;
return0
}

Output:
welcome 1
welcome 2
welcome 3
welcome 4
welcome 5
Exit from loop here

If you like this post, don’t forget to share 🙂

This article is written by our awesome writer
Comments to: continue Statement In Cpp

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

Attach images - Only PNG, JPG, JPEG and GIF are supported.

New Dark Mode Is Here

Sign In to access the new Dark Mode reading option.

Join our Newsletter

Get our monthly recap with the latest news, articles and resources.

By subscribing you agree to our Privacy Policy.

Latest Articles

Explore Tutorials By Categories

About

Codeverb is simply an all in one interactive learning portal, we regularly add new topics and keep improving the existing ones, if you have any suggestions, questions, bugs issue or any other queries you can simply reach us via the contact page

Login

Welcome to Codeverb

Ready to learn something new?
Join Codeverb!

Read Smart, Save Time
  •  
    Strength indicator
  •  
  •  
    Log In | Lost Password