Topic 50 of 100 Control Flow in C Interactive Tutorial

C continue Statement: Skipping the Current Loop Iteration

10 mins read Last updated: 22 Aug 2026 20,700 views
C Compiler 0.00%

What is C continue Statement? Core Concept & Direct Summary

Core Objective & Problem Statement

How does the `continue` statement skip the remainder of the current loop body and proceed to the next iteration?

Direct Answer Summary

Last time, we mastered break — the emergency exit that ends a loop entirely. But sometimes you don't want to abandon the loop. You just want to skip this particular pass and move on to the next one. A bad data entry in a list of a thousand? Skip it, process the rest. An even number when you're hunting odds? Skip, keep counting.

That's precisely the job of continue: abandon the rest of the current iteration and jump straight to the next one. If break is leaving the cinema halfway through the movie, continue is skipping a song on a playlist — the playlist itself keeps playing.

It's a small statement with subtle behavior — and one genuine trap in while loops that has caught nearly every C programmer at least once. Let's cover it properly.

(Suggested image: the hero diagram — a loop circle with iterations shown as boxes; on iteration 3, a "continue" arrow skips the remaining body code and arcs straight to the next iteration's start)

How Does C continue Statement Work? In-Depth Mechanics & Architecture

The Syntax

One keyword, one job: skip everything below it in the loop body, and start the next iteration immediately. The loop itself does not end — it carries on as long as its condition allows.

The classic first example:

main.c
Run Online
#include <stdio.h>
int main() {
    for (int i = 1;
    i <= 10;
    i++) {
        if (i % 2 == 0) {
            continue;
            // even? skip it.
        }
        printf("%d ", i);
    }
    return 0;
}

Output:

Every even number triggers continue, which skips the printf for that pass only. The loop still completes all ten iterations — five of them just got cut short. Compare with the same loop using break:

main.c
Run Online
if (i % 2 == 0) {
    break;
    // Output would be: 1   (loop dies at i = 2!)
}

Same position, same condition — completely different outcome. That's the difference in action.


continue vs break: The Definitive Comparison

continuebreak
What it skipsRest of this iterationThe entire loop
Loop's fateKeeps loopingEnds immediately
Works in switch?✗ No✓ Yes
Typical useFiltering — skip bad/unwanted itemsSearch — stop when found
AnalogySkip a songStop the playlist

Side by side, one frame at a time:

main.c
Run Online
for (int i = 1;
i <= 5;
i++) {
    if (i == 3) continue;
    printf("%d ", i);
}
// 1 2 4 5     ← 3 skipped, loop survived
for (int i = 1;
i <= 5;
i++) {
    if (i == 3) break;
    printf("%d ", i);
}
// 1 2         ← loop died at 3

(Suggested image: this exact comparison as a two-panel infographic — this targets the very high-volume "break vs continue" query; make it excellent)


How continue Behaves in Each Loop — This Is Where It Gets Tricky

Here's the subtle part most tutorials gloss over: what "next iteration" means differs by loop type. Specifically — does the update happen or not?

In a for loop: update RUNS ✓

main.c
Run Online
for (int i = 1;
i <= 5;
i++) {
    if (i == 3) continue;
    printf("%d ", i);
}
// 1 2 4 5 — safe!

continue in a for jumps to the update step (i++) and then the condition. The counter still advances. Life is good.

In a while loop: update might NOT run ⚠️

main.c
Run Online
int i = 0;
while (i < 5) {
    i++;
    // update BEFORE continue — safe    if (i == 3) continue;
    printf("%d ", i);
}
// 1 2 4 5

But watch what happens when the update sits below the continue:

main.c
Run Online
int i = 0;
while (i < 5) {
    if (i == 3) continue;
    // i is 3 forever now...    printf("%d ", i);
    i++;
    // ← never reached when i == 3!
}
// 1 2 ...then silence. INFINITE LOOP.

Here's the story: continue in a while jumps straight to the condition check — nothing else. The i++ below never executes, i stays 3, the condition stays true, and the loop spins forever. The condition i == 3 keeps matching, continue keeps firing, and i++ is permanently ghosted.

The rule: in while and do-while, make sure your update happens before any possible continue — or your loop may never move again.

In a do-while loop: jumps to the condition

main.c
Run Online
int i = 0;
do {
    i++;
    if (i == 3) continue;
    // safe — i++ already happened above    printf("%d ", i);
} while (i < 5);
// 1 2 4 5

continue here jumps to the condition check at the bottom. Same update-placement rule as while — update first, skip second.

(Suggested image: a three-row diagram showing exactly where continue jumps in for (→ update), while (→ condition), do-while (→ condition). This visual explains the trap better than any paragraph.)


The Classic Use Cases

Filtering input — process only valid entries:

main.c
Run Online
#include <stdio.h>
int main() {
    int sum = 0, count = 0, num;
    puts("Enter 5 positive numbers:");
    while (count < 5) {
        printf("> ");
        scanf("%d", &num);
        if (num <= 0) {
            puts("Positive numbers only — skipped.");
            continue;
            // don't count it, don't add it        }
            sum += num;
            count++;
        }
        printf("Sum of valid entries: %d\n", sum);
        return 0;
    }

Sample Run:

main.c
Run Online
Enter 5 positive numbers:> 10> -4Positive numbers only — skipped.> 20> 0Positive numbers only — skipped.> 30> 5> 15Sum of valid entries: 80

Skipping specific values — print 1–20 except multiples of 3:

main.c
Run Online
for (int i = 1;
i <= 20;
i++) {
    if (i % 3 == 0) continue;
    printf("%d ", i);
}
// 1 2 4 5 7 8 10 11 13 14 16 17 19 20

Guard-clause style — keep the main logic flat:

main.c
Run Online
for (int i = 0;
i < size;
i++) {
    if (data[i] == INVALID) continue;
    // skip junk    if (data[i] < 0) continue;
    // skip negatives    // main processing sits here, un-nested and readable    process(data[i]);
}

That last pattern is quietly one of the most valuable uses of continue: instead of wrapping real work in layer after layer of if, you reject the bad cases up front and keep the happy path at normal indentation. It pairs beautifully with the "guard clauses" idea from our nested-if tutorial.


continue in Nested Loops

Same rule as break: continue affects only the loop it physically sits in:

main.c
Run Online
for (int row = 1;
row <= 3;
row++) {
    for (int col = 1;
    col <= 3;
    col++) {
        if (row == col) continue;
        // skip the diagonal        printf("[%d,%d] ", row, col);
    }
    printf("\n");
}

Output:

main.c
Run Online
[1,2] [1,3][2,1] [2,3][3,1] [3,2]

Only the inner loop skips; the outer loop never even notices. [1,1], [2,2], [3,3] — the diagonal — vanished, and everything else printed. (Handy trivia: this exact pattern is how you skip matrix diagonals, coming soon in the arrays section.)


The Common continue Mistakes

  1. The while-loop infinite trap — update below continue never runs. The #1 continue bug, worth repeating until it sticks.
  2. Confusing it with break — continue doesn't end anything; the loop lives on. If your loop "should have stopped," check whether you wanted break.
  3. Using it in switch expecting to skip cases — illegal; continue belongs to loops only. (If the switch sits inside a loop, continue skips to the loop's next iteration — legal, but read it twice before writing it.)
  4. Code after continue in the same block — unreachable dead code:
    main.c
    Run Online
    if (invalid) {
        continue;
        printf("never prints\n");
    }
  5. Using it where a plain if reads better:
    main.c
    Run Online
    // With continue:
    for (...) {
        if (x % 2 == 0) continue;
        printf("%d ", x);
    }
    // Without — arguably cleaner for one condition:
    for (...) {
        if (x % 2 != 0) {
            printf("%d ", x);
        }
    }
    continue earns its place when there are multiple skip conditions or deep nesting to avoid. For a single simple condition, an inverted if is often clearer. Judgment, not dogma.

(Suggested image: "5 continue Mistakes" checklist graphic — consistent with the series)


A Complete Example: Report Card Processor

main.c
Run Online
#include <stdio.h>
int main() {
    int n, mark, pass = 0, fail = 0, absent = 0, total = 0;
    printf("How many students? ");
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        printf("Marks for student %d (-1 if absent): ", i);
        scanf("%d", &mark);
        if (mark == -1) {
            absent++;
            continue;
            // absent — skip grading entirely
        }
        if (mark < 0 || mark > 100) {
            puts("Invalid marks — re-entering not counted.");
            i--;
            // retry this student
            continue;
        }
        total += mark;
        if (mark >= 40) pass++;
        else fail++;
    }
    int graded = pass + fail;
    puts("\n===== REPORT =====");
    printf("Passed : %d\n", pass);
    printf("Failed : %d\n", fail);
    printf("Absent : %d\n", absent);
    if (graded > 0) {
        printf("Average: %.2f\n",(float)total / graded);
    }
    return 0;
}

Sample Run:

main.c
Run Online
How many students? 4
Marks for student 1(-1 if absent): 78
Marks for student 2(-1 if absent): -1
Marks for student 3(-1 if absent): 150
Invalid marks — re-entering not counted.
Marks for student 3(-1 if absent): 35
Marks for student 4(-1 if absent): 92
===== REPORT =====
Passed : 2
Failed : 1
Absent : 1
Average: 68.33

Two different continues doing two different jobs — one filtering absentees, one forcing re-entry on invalid input — while the average correctly excludes both. That's filtering logic exactly as it appears in real programs.


Final Thoughts

continue completes your loop-control toolkit. Where break ends the story, continue just turns the page — skipping the parts that don't matter while keeping the loop's momentum. Filtering, validation, guard clauses: anywhere a loop meets imperfect data, continue is how you say "not this one — next."

Burn the one real trap into memory: in while and do-while, update before you continue. Do that, and this little statement will never hurt you.

And with that — the Control Flow cluster is complete. Decisions (if, if-else, nested, switch), loops (for, while, do-while), and jumps (break, continue): you now hold every tool C gives you for controlling what runs and when. Everything from here — arrays, functions, pointers — builds on this foundation.

Runnable C Code Example & Practical Implementation

main.c
Run Online
#include <stdio.h>
int main() {
    printf("Printing odd numbers between 1 and 10:\
");
    for (int i = 1; i <= 10; i++) {
        if (i % 2 == 0) {
            continue;
            // Skip even numbers
        }
        printf("  %d\
", i);
    }
    return 0;
}

Key Takeaways, Best Practices & Memory Safety Rules

Best Practice & Key Takeaways
Ensure loop increment logic occurs before any continue statements in while loops, or prefer for loops where increments are handled in the header.

Frequently Asked Questions & Technical Interview Insights

Technical Interview & Viva Questions

Frequently asked C programming interview questions
Q

Q: What is the danger of using `continue` inside a `while` loop?

A: If the loop counter increment `i++` is placed at the bottom of the loop body, `continue` skips it, causing the loop condition to remain true and creating an infinite loop.
Q

Q: What is the difference between `break` and `continue`?

A: `break` terminates the entire loop immediately; `continue` terminates only the current iteration and starts the next iteration.

Related Tools, Tutorials & Authoritative References

Recommended Interactive Tools

Authoritative Standards & Citations