Home » Syntax References

Syntax of continue statement in C/C++ programming language

C/C++ programming language continue statement: what is break, when it is used and how, where t is used? Learn about continue statement with Syntax, Example.

continue is a keyword in C, C++ programming language and it is used to transfer the program’s control to starting of loop. It continues the execution of loop without executing the statements written after continue within the loop body.

Here, is the syntax of continue statement with loop statement in C/C++ programming:

for (counter_initialization; test_condition; counter_increment)
{
	//statement(s)
	if(test_condition)
		continue;
	//statement(s)
}

If the test_condition written within the loop body is true (non zero) value, statement(s) written after the continue will not print and program’s control will move to the beginning.

Consider the given example:

#include <stdio.h>

int main()
{
	int loop; //loop counter 
	
	for(loop =1; loop<=10; loop++)
	{
		if(loop==7)
		{
			printf("continue...\n");
			continue;
		}
		printf("%d\n",loop);
	}
	
	printf("BYE BYE!!!\n");
	
	return 0;
}

Output

1 
2 
3 
4 
5 
6 
continue... 
8 
9 
10
BYE BYE!!!

Consider the output, when value of loop is 7 program printed “continue...” written within the condition and without printing 7 (that value of loop at the time) program’s control reached to the starting of loop (i.e. to the loop’s test_condition).



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.