The Continue statement in C Programming is another one that controls the flow of loops such as For Loop, While Loop, and Do While Loops. While executing these loops, if the compiler finds the continue statement inside them, then the loop will stop the current iteration and start the new iteration from the beginning.
In the C continue Statement example, we have 10 statements inside the loop. And we want to skip executing the second 5 lines (statement6 —statement10) when a certain condition is True, or else it has to execute all the 10 lines inside the loop. In these situations, we place the condition after the 5th statement, followed by this continue statement. If the condition is True, then it will stop executing statements 6 to 10. Otherwise, it will execute lines 1 to 10.
The syntax of the Continue Statement in C Programming is as follows:
continue;
Continue statement in C Example
In this article, We would like to share two examples to display the working functionality of the Continue statement in both the For loop and the While loop.
C Continue Statement inside For Loop Example
In this example, we will show you how to use the Continue Statement inside the For Loop with an example. This program allows the user to enter any integer values. Then it will display the Even and Odd numbers inside the integer value.
#include <stdio.h>
int main()
{
int i, number;
printf("\n Please Enter any integer\n");
scanf("%d", &number);
for(i=1;i<= number; i++)
{
if(i%2 != 0)
{
printf("\n Odd Numbers = %d(Skipped By Continue)\n",i);
continue;
}
printf("\n Even numbers = %d\n",i);
}
}

Within this continue Statement in for loop program example,
- Here we are not going to explain the for loop. If you don’t understand for loop, please visit our article For Loop in C Programming.
- Inside the for loop, we placed the If condition to test whether (i%2 != 0). If this condition is True, the continue statement will execute, and the iteration will stop at that number without printing the other printf function: printf(“\n Even numbers = %d\n”, i).
- If the condition is false, it skips the continue statement and prints that number as output (In Our case, Even Number)
C Continue Statement inside While Loop Example
This continue program is the same as the above example. However, we replaced the for loop with a while loop.
#include<stdio.h>
int main()
{
int i=0;
while (i<= 10)
{
if (i== 5 || i == 9)
{
printf("Skipped Values = %d\n", i);
i++;
continue;
}
printf("Values = %d\n", i);
i++;
}
return 0;
}

Values = 0
Values = 1
Values = 2
Values = 3
Values = 4
Skipped Values = 5
Values = 6
Values = 7
Values = 8
Skipped Values = 9
Values = 10
Within this C continue Statement in the while loop example, Here we are not going to explain the While loop. Please visit our While Loop in C and Do While loop articles in C Programming.
Inside the While loop, we placed the If condition to test whether i is equal to 5 or 9. If this condition is True, the continue statement will run, and the iteration will stop at that number without printing the other printf: printf(“Values are: %d “, i);.
For better understanding, we placed printf(“Skipped Values = %d\n “, i); inside the If condition. So, whenever the iteration breaks, that value is printed from this printf. If the condition is false, then it will skip the continue statement and print that number as output (In Our case, 0,1,2,3,4,6,7,8,10)
How to skip odd numbers using the C continue statement?
It is one of the common scenarios to use the continue statement to skip unwanted data in a range, arrays, etc. This program prints the even numbers in a range (1 to 10) by skipping the odd numbers using the continue statement.
In the following example, the for loop iterates the i value from 1 to 10 to print those numbers. Inside it, the if statement uses the modulus operator to check whether the i value is not completely divisible by 2. If true, it’s an odd number, so the compiler executes the continue statement and skips the current iteration without printing the number.
#include <stdio.h>
int main()
{
int i;
for (i = 1; i <= 10; i++)
{
if (i % 2 != 0)
{
continue;
}
printf("%d\n", i);
}
return 0;
}
2
4
6
8
10
C continue statement inside nested loops
Similar to the break statement, the continue statement is subject to the current loop where it resides. If we use the continue statement in a nested loop, it will affect that innermost loop and not affect the outer (main) loop.
In the following example, the main for loop iterates from 1 to 2 (a total of two iterations). The nested loop must iterate from 1 to 3 (a total of three iterations). Inside the nested loop, the if statement checks whether j becomes 2; if true, execute the continue statement. On each row iteration, when j becomes 2, skip that number and move the nested loop to the next iteration.
#include <stdio.h>
int main()
{
int i, j;
for (i = 1; i <= 2; i++)
{
for (j = 1; j <= 3; j++)
{
if (j == 2)
{
continue;
}
printf("i = %d, j = %d\n", i, j);
}
}
}
i = 1, j = 1
i = 1, j = 3
i = 2, j = 1
i = 2, j = 3
What is the difference between break and continue in C?
Both break and continue statements are helpful to alter the flow of a program. However, they are both different.
- break statement will exit the current loop. When the compiler encounters a break statement, it moves outside the current loop.
- continue statement skips the current iteration of the loop and moves to the next iteration of the loop.
The following examples explain the difference between the break and continue statements.
break example
Here, the for loop starts from 0 to 5 to print those numbers. However, the if statement checks whether the current iteration value is equal to 2. If true, it executes the break statement and the compiler exits the loop.
#include <stdio.h>
int main()
{
int i;
for (i = 0; i <= 5; i++)
{
if (i == 2)
{
break;
}
printf("%d\n", i);
}
}
0
1
continue example
In this example, we replaced the break statement with the continue statement to show the difference. Here, when the current iteration value becomes 2, the compiler will execute the continue statement. It skips the current iteration without printing the i value and moves to the next iteration (i = 3).
#include <stdio.h>
int main()
{
int i;
for (i = 0; i <= 5; i++)
{
if (i == 2)
{
continue;
}
printf("%d\n", i);
}
}
0
1
3
4
5