C continue Statement

Beginner
⏱️ 11 min read
📚 Updated: Jul 2026
🎯 5 Examples
Skip iteration

What You’ll Learn

The continue statement skips the rest of the current loop iteration and moves to the next one. The loop keeps running—unlike break, which exits entirely. Use it to ignore even numbers, skip invalid entries, or bypass values you do not need to process. This tutorial covers for, while, and do-while, with five examples and pitfalls to avoid.

01

Skip body

One iteration.

02

Loop stays

Not break.

03

for safe

i++ runs.

04

while care

Increment first.

05

Filter

Skip evens.

06

No switch

Loops only.

Definition and Usage

The continue statement ends the current iteration of the nearest enclosing loop and jumps to the next cycle. Any statements below continue in that iteration are not executed.

Use continue when you want the loop to keep going but skip certain values or cases—print only odds, ignore negatives, or bypass empty records. Compare with break, which stops the loop completely when you are done.

💡
Beginner Tip

In a for loop, continue still runs the increment step (i++). In a while loop, increment before continue if needed, or you may loop forever on the same value.

📝 Syntax

The continue statement is a single keyword and semicolon:

C
continue;

Where it is valid

  • Inside loopsfor, while, do-while.
  • Not in switch — use break to leave a case.
  • Not at file scope — must be inside a loop body.

Effect on control flow

C
for (int i = 0; i < n; i++) {
    if (skip_condition) {
        continue;   /* jump to i++ and next test */
    }
    /* this line is skipped when continue runs */
}
/* loop may still be running or finished */

Compile

C
gcc program.c -std=c11 -o program

⚡ Quick Reference

ContextWhat continue does
for loopSkip to increment (i++), then condition check
while / do-whileSkip to condition check; update counter before continue if needed
vs breakcontinue = next iteration; break = leave loop
switchNot allowed in C
Nested loopsAffects innermost loop only (like break)
Syntax
continue;

One keyword

Loop
keeps going

Not exit

for
i++ runs

After continue

while
watch i++

Infinite risk

Examples Gallery

Compile with gcc example.c -std=c11 -o example. Each program shows continue in a different situation.

📚 Getting Started

Skip specific iterations in for and while loops.

Example 1 — continue in a for Loop

Print 0–4 except 2.

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

When i == 2, printf is skipped but i++ still runs, then the loop tests i < 5 again with i == 3.

Example 2 — continue in a while Loop

Skip printing 2 and 4; increment at the start of each iteration.

C
#include <stdio.h>

int main(void) {
    int i = 0;

    while (i < 5) {
        i++;
        if (i == 2 || i == 4) {
            continue;
        }
        printf("%d\n", i);
    }

    return 0;
}

How It Works

i++ runs before the skip test, so continue does not trap the loop on the same value. Without that increment, an infinite loop is possible.

📈 Practical Patterns

Safe incrementing, filtering, and data processing.

Example 3 — Avoiding an Infinite Loop

Increment before continue when the counter update comes after the skip point.

C
#include <stdio.h>

int main(void) {
    int i = 0;

    while (i < 5) {
        if (i == 2) {
            i++;
            continue;
        }
        printf("%d\n", i);
        i++;
    }

    return 0;
}

How It Works

At i == 2, we increment to 3 before continue, so the loop advances. Without i++ there, i would stay 2 forever. This pattern is from the reference best-practices section.

Example 4 — Print Only Odd Numbers

Skip even values with continue.

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

Even i values hit continue and skip printf. The loop still visits every number 1–10—a classic filter pattern.

Example 5 — Sum Positive Values Only

Skip negatives when summing an array.

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

-3, 0, and -1 trigger continue, so only 10, 5, and 8 are added. The loop processes every element without nested if-else around the whole body.

🚀 Common Use Cases

  • Filter values — skip evens, negatives, or out-of-range items.
  • Input loops — ignore blank lines and re-prompt.
  • Data processing — skip null or invalid records in a list.
  • Game loops — skip inactive entities each frame.
  • Retry logic — skip to next attempt without leaving the loop.
  • Cleaner code — avoid deep nesting with early skip.

🧠 How continue Works

1

Condition to skip

An if test decides this iteration should be skipped.

Trigger
2

Run continue

Remaining statements in the loop body are bypassed.

Skip
3

Next iteration

In for, increment runs; then the loop condition is tested again.

Cycle
=

Loop continues or ends

If the condition is still true, the next iteration starts. Otherwise the loop finishes normally.

📝 Notes

  • continue is only valid inside loops, not in switch.
  • In for, the increment expression runs after continue.
  • In while, ensure the counter changes before continue when needed.
  • continue affects the innermost enclosing loop only.
  • Do not confuse continue with break or return.
  • Too many continue statements can hurt readability—sometimes an if wrapping the body is clearer.

⚡ Optimization

continue has negligible overhead. Skipping unwanted work early can save time when processing large arrays. Some programmers prefer a single if that wraps the main logic instead of continue—choose whichever reads clearer. Modern compilers optimize both styles similarly.

Conclusion

continue lets you skip one loop iteration while keeping the loop alive. It is ideal for filtering values and simplifying loop bodies. Watch counter updates in while loops, and remember it is not valid in switch.

You now know break (exit) and continue (skip). Next: the rarely used goto statement.

💡 Best Practices

✅ Do

  • Increment loop counters before continue in while
  • Use continue to skip clearly unwanted values
  • Prefer for when skipping many iterations (safer increment)
  • Keep skip conditions simple and well named
  • Compare mentally with break before choosing

❌ Don’t

  • Use continue in switch (invalid in C)
  • Forget to update counters in while before continue
  • Scatter many continues that make flow hard to follow
  • Use continue when break is what you need
  • Rely on continue to fix poorly structured loops

Key Takeaways

Knowledge Unlocked

Five things to remember about continue

Skip one iteration in C.

5
Core concepts
02

Loop stays

Not break.

Flow
🔢 03

for + i++

Still runs.

Safety
📝 04

while

Increment first.

Pitfall
📈 05

Filter

Skip evens.

Pattern

❓ 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.
Did you know?

In a for (init; cond; incr) loop, continue jumps to incr, not back to the top of the body. That is why continue in for rarely causes infinite loops, while the same logic in while can if you forget to advance the counter.

Continue to goto

Learn about goto—the unconditional jump statement (use sparingly).

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.

6 people found this page helpful