Skip to main content

Purpose of continue statement

Short answer

The continue statement skips the remaining statements of the current loop iteration and immediately proceeds to the next iteration. It can only be used inside loops: for, while, and do-while.

What are the purpose of the continue statement? Within which control statements can continue statement be included?

Purpose of continue

The continue statement skips the remaining statements of the current iteration of a loop and moves control directly to the next iteration (in a for loop, to the update expression; in while and do-while, to the condition test). It lets us ignore particular cases without leaving the loop.

#include <stdio.h>
int main(void)
{
    int i, sum = 0;
    for (i = 1; i <= 10; i++)
    {
        if (i % 2 == 0)
            continue;       /* skip even numbers */
        sum += i;
    }
    printf("Sum of odd numbers 1..10 = %d\n", sum);
    return 0;
}

Output:

Sum of odd numbers 1..10 = 25

Where it can be used

continue can be used only inside loops: for, while and do...while. It may be written inside an if or a switch that is itself inside a loop, but not outside a loop.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Computer Programming chapter 5 questions →