Advertisement



< Prev
Next >



C++ Continue Statement





C++ language provides a loop control statement known as continue, which is also used within a loop. When a continue statement is encountered in an executing loop of a program, it skips executing the rest of statements in the loop for that particular iteration and the program continues with the next iteration and condition checking in the loop.






Continue statement example


// C++ continue statement example 

#include<iostream>

int main() // main method and program begins here
{ 


for(int i=0;i<5;i++)
{	
	if(i==3)
		continue;

	cout<<"i = " << i <<"\n";
}

cout<<"We are out of the loop");

return 0;
} // main method ends and so does the program


Output


i = 0
i = 1
i = 2
i = 4
We are out of the loop

As you may see in the output of the program, when continue statement was encountered within an executing for loop, it skipped executing the printf() statement in the loop for that particular iteration i.e. when i is equal to 3. The program continued normally with the next iteration(i is equal to 4) and condition checking.


Advertisement




Please share this article -





< Prev
Next >
< Switch Statement
Goto Statement>



Advertisement

Please Subscribe

Please subscribe to our social media channels for daily updates.


Decodejava Facebook Page  DecodeJava Twitter Page Decodejava Google+ Page




Advertisement



Notifications



Please check our latest addition

C#, PYTHON and DJANGO


Advertisement