C++ Continue Statement

Continue statement is used to transfer control to the start point of control structure. It is most commonly used in iterative structures.

Example

The given example uses continue statement in while loop.

#include <iostream>
using namespace std;

int main(int argc, char** argv) {
	
	int a = 0;
	
	while ( a< 10) {
		
		a = a + 1; // here we can also write a++
		
		if(a > 5)
		     continue; // here continue is used to continue loop.
		               // and skip remaining statements.
		cout<<a<<"\n";
	}
	
	return 0;
}

In above example while loop will iterate 10 times but only 5 numbers will print. Because when counter variable will greater than 5 continue statement will transfer the control to the beginning of loop.

Comments
Login to TRACK of Comments.