Continue Statement in C
In this article, you will come to know about the continue statement in C and how it works in the program.
Continue Statement in C
The continue statement skips the current iteration of the loop and forces the next iteration of the loop to take place. Continue is a loop control statement just opposite to that of the break statement, as it forces the next iteration of the loop to execute by skipping the code in between.
The continue statement is mainly used for a condition so that we can skip some code for a particular condition. It is mostly used with the if..else statement.
Syntax
continue;
Example
#include <stdio.h>
int main()
{
for (int i = 0; i < 10; i++)
{
if (i == 5)
continue;
else
printf("%d ", i);
}
return 0;
}
Output
0 1 2 3 4 6 7 8 9
The above example is a program of printing a series of numbers with an exception(i.e. 5 here).
So when the value of i becomes 5 it skips that particular iteration and proceeds with the next as we have given the continue statement for the condition if (i == 5).