Python continue Statement

Learn how the Python continue statement works in for loops, while loops, if conditions, and nested loops, with examples, flowchart, break vs continue, and common mistakes.

Published

Updated

Read time 7 min read

Reviewed byDeepak Prasad

Python continue Statement

If you have ever wanted to skip one turn of a loop without stopping the whole loop, you are looking for continue. Here you will see what it does in a plain for loop and a while loop, how it differs from break and pass, what happens with nested loops and with a loop else, and one while foot-gun that catches a lot of people. The page is short on purpose so you can try the examples as you read.

When you want the official wording, open the Python language reference for continue: it says continue proceeds to the next iteration of the nearest enclosing loop, or to the loop’s else when there is no next item. If you are still getting comfortable with loops themselves, skim the while loop tutorial next.

Tested on: Python 3.13.3; kernel 6.14.0-37-generic.


What does continue do in Python?

Think of one lap around a track. continue means “stop the rest of this lap, start the next lap.” It does not mean “leave the stadium”; that is what break does. Only the lines below continue in the same iteration are skipped; the loop keeps running.

Try this in your head (or in the REPL): when number is 3, you skip print, but you still move on to 4 and 5.

python
for number in range(1, 6):
    if number == 3:
        continue
    print(number)
Output

You should see 1, 2, 4, and 5 on separate lines—notice 3 never prints.

Flowchart showing Python continue skipping the remaining loop body and returning to the next iteration


Python continue syntax

You write the keyword on its own line:

python
continue
Output

You can only use it inside a for or while loop. If you put it at the top level of a file, Python raises SyntaxError, which matches the rule above.


continue in a for loop

Inside a for loop, after continue Python grabs the next value from whatever you are iterating over and runs the body again from the top.

Suppose you want to print every country except one—you still visit "China" in the loop, you just skip the print for that pass.

python
countries = ["India", "Nepal", "Sri Lanka", "China", "Australia"]
for country in countries:
    if country == "China":
        continue
    print(country)
Output

You get India, Nepal, Sri Lanka, and Australia, each on its own line.


continue in a while loop

With a while loop, after continue Python jumps back and checks the while condition again. That means you still need to update whatever drives that condition, or you can spin forever (there is a concrete example in Common mistakes).

Here multiples of 5 are skipped, but i still moves forward on every path so the loop can finish.

python
i = 1
while i <= 10:
    if i % 5 == 0:
        i += 1
        continue
    print(i)
    i += 1
Output

You should see 1 through 4, then 6 through 9—no 5 or 10 in the output.


continue with if condition

There is no special continue keyword for if; you almost always tuck continue under an if so you only skip some passes. If you already use if / else, this is the same idea.

python
for n in range(5):
    if n % 2 == 0:
        continue
    print(n)
Output

Here you only print odd numbers (1 and 3). If the body is tiny, some people prefer if n % 2 != 0: print(n) instead of continue; pick whichever reads better to you.


continue vs break in Python

When you are learning, keep this table nearby:

Statement What it does for you
continue Skips the rest of this iteration and starts the next one in the same loop
break Stops the whole loop and jumps to the code after the loop
pass Does nothing; handy placeholder where Python needs a statement

If you are also learning when a loop else runs, the Python break statement article walks through how break interacts with that else.

Comparison diagram showing continue returning to the loop header while break exits the loop completely


continue vs pass in Python

pass is a no-op: execution keeps moving down the same iteration. continue jumps straight to the next iteration, so anything below it in the body for this pass does not run.

First, with pass—you still print every number:

python
for number in range(1, 4):
    if number == 2:
        pass
    print(number)
Output

You should see 1, then 2, then 3.

Now swap in continue2 never reaches print:

python
for number in range(1, 4):
    if number == 2:
        continue
    print(number)
Output

You should see 1, then 3.


continue in nested loops

When loops nest, continue only affects the innermost loop that wraps it. If you are in an inner for inside an outer for, your continue applies to the inner one.

python
for row in range(3):
    for col in range(3):
        if col == 1:
            continue
        print(row, col, end="  ")
    print()
Output

Whenever col is 1, you skip printing for that column only; the outer row loop still advances as normal.


continue with loop else clause

You can attach an else to a for or while. That else runs when the loop finishes without hitting break. The tutorial is clear: continue does not cancel that else—it only skips the tail of the current iteration. If you never break, you still get the else after the last item.

python
for n in range(3):
    if n == 1:
        continue
    print(n)
else:
    print("loop else: finished without break")
Output

You should see 0, then 2, then the message from the else block.


Common mistakes with continue

Here are the mix-ups I see most often:

  • You think continue exits the loop—it does not; only break does.
  • In a while loop, you hit continue before you change the variable that the while line depends on, so the condition never becomes false (infinite loop).
  • You use continue outside any loop and get SyntaxError.
  • You stack many continue branches when one straightforward if would read easier.
  • You assume continue skips the loop else; it does not—only break changes that story.
  • You treat pass like continue; remember pass does not skip the rest of the body.

Infinite while with continue

This pattern hangs because when i is 2, you never reach i += 1, so i stays 2 forever:

python
# Bug: when i == 2, continue skips i += 1, so i stays 2 forever
i = 0
while i < 5:
    if i == 2:
        continue
    print(i)
    i += 1
Output

Do not run that snippet as-is in a REPL unless you are ready to interrupt it.

Safer pattern

Bump your counter (or otherwise make progress) before you continue, or restructure so the update cannot be skipped:

python
i = 0
while i < 5:
    i += 1
    if i == 2:
        continue
    print(i)
Output

You should see 1, 3, 4, 5—each on its own line.


Python continue quick reference table

What you want What to write
Skip the rest of this iteration, keep looping continue
Stop the loop completely break
Placeholder that does nothing pass
Skip only when a condition holds if cond: continue
Which loop does continue affect? The innermost for or while around it
Does continue skip loop else? No—only break changes whether else runs

Summary

You use continue when you want to abandon the rest of this lap around a for or while, but you still want the loop itself to keep going. It is not break, it is not pass, and it does not trick Python into skipping a loop else if the loop finishes normally. In while loops, always ask yourself whether the line that moves you toward exit still runs on every path—including paths where you hit continue. When you are ready to pair this with leaving loops early, read the break statement guide next.


References


Frequently Asked Questions

1. What does continue do in Python?

continue skips the rest of the current loop body and jumps to the next iteration of the innermost enclosing loop; it does not exit the loop.

2. What is the difference between continue and break in Python?

continue skips the rest of the current iteration and keeps looping; break leaves the loop entirely and execution continues after the loop.

3. Does continue skip the else clause on a for or while loop?

No. If the loop finishes without break, the else suite still runs; continue does not count as leaving the loop early the way break does.

4. Can you use continue outside a loop?

No. continue may only appear inside a for or while loop; using it elsewhere is a SyntaxError.
Deepak Prasad

R&D Engineer

Founder of GoLinuxCloud with more than 15 years of expertise in Linux, Python, Go, Laravel, DevOps, Kubernetes, Git, Shell scripting, OpenShift, AWS, Networking, and Security. With extensive …