0
0
Cprogramming~5 mins

Continue statement

Choose your learning style9 modes available
Introduction

The continue statement helps skip the rest of the current loop cycle and move to the next one. It lets you avoid running some code inside a loop when a condition is met.

When you want to skip processing certain items in a loop but continue looping.
When filtering data inside a loop and ignoring unwanted cases.
When you want to avoid nested if-else blocks by skipping early in a loop.
When you want to improve readability by handling special cases first and continuing.
When you want to jump to the next iteration without breaking the whole loop.
Syntax
C
continue;

The continue statement is used inside loops only (for, while, do-while).

It immediately skips to the next iteration of the loop.

Examples
This loop prints numbers 0 to 4 but skips printing 2 because of continue.
C
for (int i = 0; i < 5; i++) {
    if (i == 2) {
        continue;
    }
    printf("%d ", i);
}
This while loop skips printing 3 and continues with the next numbers.
C
int i = 0;
while (i < 5) {
    i++;
    if (i == 3) {
        continue;
    }
    printf("%d ", i);
}
Sample Program

This program prints only odd numbers from 1 to 10 by skipping even numbers using continue.

C
#include <stdio.h>

int main() {
    for (int i = 1; i <= 10; i++) {
        if (i % 2 == 0) {
            continue;  // Skip even numbers
        }
        printf("%d ", i);
    }
    return 0;
}
OutputSuccess
Important Notes

Using continue can make loops easier to read by handling special cases early.

Be careful not to create infinite loops by skipping the code that changes the loop variable.

Summary

continue skips the rest of the current loop cycle and moves to the next.

It works inside for, while, and do-while loops.

Use it to ignore certain cases without stopping the whole loop.