Home / Programs / continue statement in for loop
Programming Example

continue statement in for loop

👁 1,041 Views
💻 Practical Program
📘 Step by Step Learning

The continue statement in C programming works somewhat like the break statement. Instead of forcing termination, it forces the next iteration of the loop to take place, skipping any code in between.

For the for loop, continue statement causes the conditional test and increment portions of the loop to execute. For the while and do...while loops, continue statement causes the program control to pass to the conditional tests.

 

syntax

The syntax for a continue statement in C is as follows −

continue;

Flow Diagram with syntax

 

for loop continue
Syntaxfor loop continue

Program Code

#include <stdio.h>
void main ()
{ 
int a =  1; 
 
while( a <= 10){ 
	 	
 	if(a == 5){ 
 	  a++;
      continue;
	 } 

 printf("value of a: %d\n", a);	
 a++; 	  
} 
 
}

Output

value of a: 1
value of a: 2
value of a: 3
value of a: 4
value of a: 6
value of a: 7
value of a: 8
value of a: 9
value of a: 10
Press any key to continue . . .

Explanation

when the value of a reaches to 5 then its continue, for that 5 is not printed.

How to learn from this program

First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.