Continue Statement in C with Examples

Continue Statement in C with Examples

Continue statements in C is required When we want to take the control to the beginning of the loop, bypassing the statement inside the loop, a statement not yet executed, the keyword continues to allow us to do this.

The continue statement in C programming works rather like the break declaration. Rather than forcing termination, it compels the next iteration of the loop to happen, avoiding any type of code in between.

For the for loop, continue declaration triggers the conditional test as well as increment portions of the loop to carry out. For the while as well as do … while loops, continue statement creates the program control to pass to the conditional tests.

Examples of continue statement

Example 1: C Program to Understand Continue statement

[c] #include<stdio.h> #include<conio.h> void main() { int a,b; for(a=1; a<=3;a++) { for(b=1;b<=3; b++) { if(a==b) continue; printf(" The value of a and b is%d %d\n",a,b); } } getch(); } [/c]

Output

Example 2: Skip a number using continue in C

[c] #include<stdio.h> #include<conio.h> void main() { int a; for(a=1; a<=10;a++) { if(a==5) { continue; } printf("%d\n",a); } getch(); } [/c]

Output

In the above code when the condition match, it will enter in that block and skip 5th step do to continue statement.