C continue Statement

Beginner
6 min read
Updated: Oct 2026
3 examples
Live preview

What Is continue?

continue skips the rest of the current iteration in a for, while, or do-while loop, then jumps to the next cycle. The loop keeps running—unlike break, which exits entirely.

Remember
continue;   // skip rest of this iteration

in a for    → still runs i++, then re-checks condition
in a while  → jumps to condition (update counter first!)
not in switch → use break for cases

loop keeps going — only this pass is skipped
UsePrefer
Skip unwanted valuescontinue (filter pattern)
Stop the loop completelybreak
Leave a switch casebreak (not continue)

How to Use continue in C

Place continue when the rest of this iteration should not run, but later ones should.

  1. Write a loop as usual (for, while, or do-while).
  2. Add a clear skip condition: if (skip_me) continue;.
  3. In while / do-while, update the counter before continue.
  4. Put the “real work” after the skip test so unwanted items never reach it.
PieceRequired?Role
Enclosing loopYescontinue is illegal outside loops
Skip conditionUsuallyWhen to jump to the next iteration
Counter update (while)Yes if neededAvoid infinite loops before continue

Pseudocode

Pseudocode
for each item in list:
    if item should be ignored:
        continue          // skip to next item
    process item          // only “good” items reach here

// loop finishes after all items

// while form — update first:
i = 0
while i < n:
    i = i + 1
    if i is even:
        continue
    print i

Cheat Sheet

Keep these facts handy while writing loop filters.

TopicDetail
Syntaxcontinue;
Valid infor, while, do-while only
EffectSkip rest of this iteration; loop continues
vs breakcontinue skips one pass; break leaves the loop
for + continueIncrement (i++) still runs
while + continueUpdate the counter before continue
Compilegcc file.c -std=c11 -o out

Live Preview

Simulate how continue skips iterations. Same idea as the C examples below.

Browser simulation of continue control flow (same idea as the C examples below).

Result
i = 0 → print
i = 1 → print
i = 2 → continue (skip print)
i = 3 → print
i = 4 → print

output: 0 1 3 4

Worked Walkthrough — Print Odds Only

Loop from 1 to 10 and print only odd numbers by skipping evens with continue.

Trace
for i = 1 … 10:
  if i is even → continue   // skip printf
  else → print i

1  → odd  → print
2  → even → skip
3  → odd  → print
…
10 → even → skip

Result: 1 3 5 7 9
Loop still visited every i — it just skipped the print

C Examples

Compile every example with gcc file.c -std=c11 -o out. Short programs you can copy and run.

Example 1 — continue in a for Loop

Print 0–4 except 2. In a for loop, i++ still runs after continue.

C
#include <stdio.h>

int main(void) {
    for (int i = 0; i < 5; i++) {
        if (i == 2) {
            continue;
        }
        printf("%d\n", i);
    }

    return 0;
}

How It Works

  1. Loop starts. i goes from 0 to 4.
  2. Normal passes. For 0 and 1, the if is false, so each value prints.
  3. Skip one. When i == 2, continue jumps past printf.
  4. Increment still runs. The for does i++, then continues with 3 and 4.

Example 2 — Print Only Odd Numbers

Filter with continue: skip even values, print the odds.

C
#include <stdio.h>

int main(void) {
    for (int i = 1; i <= 10; i++) {
        if (i % 2 == 0) {
            continue;
        }
        printf("%d ", i);
    }
    printf("\n");

    return 0;
}

How It Works

  1. Visit every number. The loop still runs for 1 through 10.
  2. Test even. i % 2 == 0 means “even.”
  3. Skip print. Evens hit continue and never reach printf.
  4. Print odds. Odds fall through to printf → 1 3 5 7 9.

Example 3 — Sum Positive Values Only

Skip zeros and negatives when summing an array—a practical filter pattern.

C
#include <stdio.h>

int main(void) {
    int data[] = {10, -3, 5, 0, 8, -1};
    int n = 6;
    int sum = 0;

    for (int i = 0; i < n; i++) {
        if (data[i] <= 0) {
            continue;
        }
        sum += data[i];
    }

    printf("Sum of positives: %d\n", sum);

    return 0;
}

How It Works

  1. Scan the array. Visit each element once.
  2. Reject non-positives. -3, 0, and -1 trigger continue.
  3. Add the rest. Only 10, 5, and 8 update sum.
  4. Result. 10 + 5 + 8 = 23—no deep nesting around the add.

Edge Cases & Pitfalls

Check these before relying on continue in real projects.

while

Infinite loop risk

In while / do-while, if you continue before updating the counter, the same condition repeats forever. Increment first, or prefer for.

switch

Not for switch

continue is only for loops. Inside switch, use break to leave a case.

compare

Not the same as break

continue skips one pass; break ends the loop. Mixing them up changes program logic completely.

scope

Outside a loop

continue at file or function scope (not inside a loop) is a compile error.

Performance Notes

ApproachCostBest for
continue filterStill visits every itemSkip work on bad items; clearer than deep nesting
break on findStops earlySearch when one match is enough
Nested if around bodySame work, harder to readAvoid when a top-level continue is clearer

continue itself is free. It does not reduce how many times the loop runs—it only skips the rest of that pass. Use break when you can stop early.

Key Takeaways

  • Role: skip the rest of this iteration; loop keeps going.
  • for: i++ still runs after continue.
  • while: update the counter before continue.
  • Pattern: filter unwanted values without deep nesting.

One line: continue skips this pass and keeps the loop alive—use it to filter, not to stop.

Frequently Asked Questions

continue skips the rest of the current loop iteration and jumps to the next one. The loop itself keeps running—unlike break, which exits the loop entirely.
break leaves the loop completely. continue only skips to the next iteration. Use break to stop searching; use continue to skip unwanted values while the loop runs on.
No. In C, continue is only valid inside loops (for, while, do-while). switch uses break to exit a case, not continue.
Yes, in while and do-while loops if you continue before incrementing the counter. In a for loop, continue still runs the increment step (i++), so it is usually safer there.
Yes. continue skips the rest of the body and jumps to the do-while condition check. Remember to update loop variables before continue when needed.
No. continue jumps to the for loop's increment expression, then re-checks the condition. That is why continue in for is less likely to cause infinite loops than in while.

Next: goto

Learn labeled jumps—and when to avoid them.

goto tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful