How to Use continue in Python: Absolute Beginners Tutorial

The continue statement gives you a way to skip specific iterations in a loop without stopping the loop itself. This tutorial walks through exactly how it works, where to use it, and the common mistakes that trip up new Python programmers.

When Python runs a loop, it normally executes every line in the loop body for every iteration. Sometimes you want to process only certain items and skip the rest. The continue statement handles exactly that. It tells Python: stop what you are doing for this iteration and move on to the next one.

What continue Does in Python

The continue statement is a loop control statement. It does not exit the loop — it skips whatever code remains in the current iteration and returns control to the loop header so the next iteration can begin.

Python has two other loop control statements worth knowing in comparison: break exits the loop entirely, and pass does nothing at all (it is a placeholder). continue sits in the middle: the loop keeps running, but the current pass through the body is cut short.

Here is the simplest possible example. The number 3 is skipped; every other number prints normally:

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

Output:

output
1
2
4
5

The number 3 never reaches the print call. When continue fired, Python jumped back to the top of the loop, incremented to 4, and carried on.

Note

continue is a keyword — it is not a function and takes no arguments. Writing continue() raises a SyntaxError.

How continue fits into Python's control flow

The table below compares the three loop control statements so you can see at a glance when to reach for each one:

Effect
Skips the rest of the current iteration; loop continues
Loop ends?
No — the loop keeps running
Effect
Exits the loop immediately
Loop ends?
Yes — no further iterations run
Effect
Does nothing; acts as a placeholder
Loop ends?
No — execution continues normally to the next line
code builder click a token to place it

Build a loop that prints only odd numbers from 1 to 9 using continue:

your code will appear here...
if n % 2 == 0: break for print(n) range(1,10): continue n in pass
Why: The correct order is for n in range(1,10): to set up the loop, then if n % 2 == 0: to catch even numbers, then continue to skip them, then print(n) which only runs for odd values. break and pass are distractors — break would exit the loop entirely and pass would do nothing useful here.

Using continue in a for Loop

The for loop is the most common place you will reach for continue. A typical pattern is to filter out unwanted items from a list while still processing the rest.

Skipping items in a list

Suppose you have a list of temperatures and you want to ignore any reading that is negative (a sensor error). Instead of building a separate filtered list first, you can handle it inline:

python
readings = [22, -1, 19, 31, -5, 28]

for temp in readings:
    if temp < 0:
        continue
    print(f"Valid reading: {temp}")

Output:

output
Valid reading: 22
Valid reading: 19
Valid reading: 31
Valid reading: 28

Using continue with string iteration

You can also iterate over characters in a string. The example below skips all vowels and prints only consonants:

python
word = "python"
vowels = "aeiou"

for char in word:
    if char in vowels:
        continue
    print(char, end=" ")

Output:

output
p y t h n
Pro Tip

When the only code after your if/continue block is a single expression, a list comprehension with a condition is often cleaner. Use continue when the loop body is longer or involves side effects like printing or writing to a file.

continue inside a nested for loop

continue only affects the loop it is directly inside. In a nested loop, it skips the current iteration of the inner loop — the outer loop is unaffected:

python
for row in range(1, 4):
    for col in range(1, 4):
        if col == 2:
            continue            # skips col 2 only
        print(f"({row},{col})", end=" ")
    print()                     # newline after each row

Output:

output
(1,1) (1,3)
(2,1) (2,3)
(3,1) (3,3)
spot the bug click the line that contains the bug

The loop below is supposed to print only words longer than 3 characters, skipping short ones. One line contains a bug. Click it, then hit check.

1 words = ["hi", "python", "go", "code", "it"]
2 for word in words:
3 if len(word) > 3:
4 continue
5 print(word)
The fix: Change if len(word) > 3: to if len(word) <= 3:. The condition is backwards — it skips the long words and prints the short ones. To skip words that are 3 characters or fewer, the condition should be <= 3 so that continue fires for the short ones, letting the long ones reach print.

Using continue in a while Loop

The same logic applies to while loops. When Python reaches continue, it jumps back to evaluate the while condition before the next iteration begins.

Basic while loop example

python
count = 0
while count < 8:
    count += 1
    if count % 3 == 0:
        continue
    print(count)

Output:

output
1
2
4
5
7
8

Multiples of 3 (3, 6) are skipped. Notice that count += 1 comes before the continue check. This is the critical pattern to follow in while loops.

Watch out

If you place the variable update after continue, the update never runs on skipped iterations, which can lock the loop in an infinite cycle. Always update your counter or state variable before the continue call in a while loop.

Flow diagram: what continue does to the loop

Loop starts Condition true? Loop ends false true if skip condition? yes continue no Rest of loop body
Loop flow with continue — the skip branch jumps back to the condition check, bypassing the rest of the loop body.

How to Use continue in Python

The four-step pattern below covers every situation where continue belongs. Follow this structure and you will avoid the common ordering mistakes.

  1. Write a loop

    Start with a for or while loop that iterates over a sequence or runs while a condition is true. Make sure the loop itself is correct before adding any control flow inside it.

  2. Add a condition to identify what to skip

    Inside the loop body, write an if statement that evaluates to True for the iterations you want to skip. The condition should be the opposite of what you want to process — you are describing the unwanted case.

  3. Place continue inside the if block

    Write continue as the body of the if statement. When the condition is true, Python executes continue and immediately jumps back to the loop header — none of the code below it in the loop body runs for that iteration.

  4. Place the main logic after the if block

    Write the code you want to execute for accepted iterations after the if/continue block — not inside an else. This code only runs when the skip condition was false and continue was not triggered.

"The continue statement... continues with the next cycle of the nearest enclosing loop." — Python Language Reference

Python Learning Summary Points

  1. continue skips the remainder of the current iteration and jumps back to the loop header — it does not exit the loop. Use it when you need to bypass certain items without stopping the entire loop.
  2. In a while loop, always update your counter or state variable before the continue statement. If the update comes after, it never runs on skipped iterations and you risk an infinite loop.
  3. When used inside a nested loop, continue only affects the innermost loop it is placed in. It does not skip iterations in any outer loop.
  4. continue and break are not interchangeable — continue moves to the next iteration while break exits the loop entirely. Picking the wrong one is one of the most frequent beginner mistakes in Python loop logic.
  5. Place the action code you want to run after the if/continue block rather than inside an else clause. Both approaches work, but the early-exit pattern with continue reduces nesting and keeps the loop body flat.

Understanding continue makes loop code cleaner because it eliminates deeply nested if/else structures. Instead of wrapping the main logic in an else block, you reject unwanted cases upfront and let the accepted cases flow naturally through the rest of the body. This pattern — sometimes called an early exit or guard clause — is worth building as a habit early in your Python learning.

check your understanding question 1 of 4

Frequently Asked Questions

The continue statement tells Python to skip the rest of the current loop iteration and move on to the next one. When Python encounters continue, it does not exit the loop — it simply jumps back to the loop header and starts the next iteration.

break exits the loop entirely, stopping all remaining iterations. continue only skips the current iteration and allows the loop to keep running. Use break when you want to stop looping, and use continue when you want to skip certain items but keep going.

Yes. The continue statement works in both for loops and while loops. In a while loop, continue causes execution to jump back to the condition check at the top of the loop, so you must be careful that the condition will eventually become False — otherwise you risk creating an infinite loop.

Yes, but continue only affects the innermost loop it appears in. If you have a for loop inside another for loop and you use continue in the inner loop, only the inner loop's current iteration is skipped. The outer loop continues normally.

Yes. A loop's else clause runs when the loop finishes normally — that is, without a break statement. Using continue does not prevent the else clause from running, because continue does not exit the loop.

No. Using continue outside of a for or while loop raises a SyntaxError. The continue statement is only valid inside loop bodies.

Use the modulo operator to check divisibility. For example: for n in range(10): if n % 2 == 0: continue — this skips the rest of the loop body for every even number and only processes odd values.

In a for loop, the loop variable advances to the next item in the iterable as normal — continue just skips the remaining code in the current iteration. In a while loop, the loop variable is not automatically updated; you are responsible for updating it before calling continue to avoid an infinite loop.