Definition: The continue statement is used to skip the remaining statements of the current iteration of a loop and move directly to the next iteration.
Definition: The continue statement is
used to skip the remaining statements of the current iteration
of a loop and move directly to the next iteration.
continue
is used when i == 3, the number 3 is skipped but
the loop continues with 4 and 5.
continue;
In the following program, the value 3 is skipped using the
continue statement.
#include <stdio.h>
int main()
{
int i;
for (i = 1; i <= 5; i++)
{
if (i == 3)
continue; // skip the current iteration
printf("%d ", i);
}
return 0;
}
1 2 4 5
The continue statement is used when a particular
iteration should be skipped but the loop should continue executing
the remaining iterations.
When continue is used inside a for loop,
the remaining statements of the current iteration are skipped.
Control then moves to the update expression before the next
condition check.
continue is executed
when i == 5, the statements after continue
are skipped for 5, but the loop continues with 6.
The continue statement can also be used inside a
while loop to skip the current iteration and proceed
with the next condition check.
Write a C program to print numbers from 1 to 10 while skipping
all even numbers using the continue statement.
continue statement.continue with a conditional statement.
Use a for loop from 1 to 10. If the number is divisible
by 2, use continue to skip that iteration.
The continue statement skips the remaining statements
of the current loop iteration. Unlike break, it does
not terminate the loop.
#include <stdio.h>
int main()
{
int i;
for (i = 1; i <= 10; i++)
{
if (i % 2 == 0) // check for even number
continue; // skip even numbers
printf("%d ", i);
}
return 0;
}
1 3 5 7 9
The continue statement does not exit the loop.
It only skips the current iteration. The loop continues with
the next iteration.
| break | continue |
|---|---|
| Terminates the loop completely. | Skips only the current iteration. |
| Control moves outside the loop. | Control moves to the next iteration. |
| Remaining iterations are not executed. | Remaining iterations continue normally. |
| Used when the loop must stop. | Used when one iteration must be skipped. |
continue skips the current iteration.for, while and
do-while loops.for loop, control moves to the update expression
after continue.continue is different from break.| Concept | Remember |
|---|---|
| Purpose | Skip the current iteration. |
| Syntax | continue; |
| Loop status | Loop continues. |
| Difference from break | break exits; continue skips. |
Watch a beginner-friendly explanation of the continue statement in C programming.
A short handwritten-style revision sheet for the continue statement will be provided here.
Use the mind map for quick revision of continue, skipped iterations and loop continuation.