Python Control Statements

Python Continue

Learn Python Continue with clear explanations, Python examples, and practical programming guidance.

What is the Python continue statement?

The continue statement skips the remaining code in the current loop iteration and starts the next iteration. It is useful when you want to ignore selected values while allowing the loop to continue.

Syntax of continue

for item in sequence:
    if condition:
        continue
    # code for items that were not skipped

When Python reaches continue, it does not execute the statements below it in that iteration. In a nested loop, it affects only the loop where it appears.

Skip even numbers with a for loop

This example prints only odd numbers by skipping every even number:

for number in range(1, 11):
    if number % 2 == 0:
        continue
    print(number)
Output
1
3
5
7
9

The remainder operator identifies even numbers. For an even number, continue jumps directly to the next loop iteration.

Skip a value in a string

A loop can use continue to ignore particular characters:

for character in "Python Programming":
    if character == "o":
        continue
    print(character, end="")
Output
Pythn Prgramming

Use continue in a while loop

Always update the loop variable before continuing, otherwise the condition may never change and the loop can become infinite:

number = 0

while number < 10:
    number += 1
    if number == 5:
        continue
    print(number)
Output
1
2
3
4
6
7
8
9
10

Skip negative numbers

Use continue to process only values that meet a rule:

numbers = [10, -3, 5, -8, 7]

for number in numbers:
    if number < 0:
        continue
    print(number)
Output
10
5
7

Skip selected words

Membership testing makes it easy to skip more than one word:

sentence = "Python learners can practice every day"
words_to_skip = ["can", "every"]

for word in sentence.split():
    if word in words_to_skip:
        continue
    print(word, end=" ")
Output
Python learners practice day

Skip empty strings

This pattern is helpful when cleaning a list before processing its values:

words = ["apple", "", "banana", "cherry", ""]

for word in words:
    if word == "":
        continue
    print(word)
Output
apple
banana
cherry

continue versus break

StatementEffectUse it when
continueSkips only the current iteration.The loop should keep processing later items.
breakStops the entire loop immediately.The required result has been found or processing must stop.
passDoes nothing.A syntactic placeholder is needed for unfinished code.

Common mistakes

  • Put the condition before continue so only the intended values are skipped.
  • In a while loop, update the counter before continuing.
  • Remember that continue skips the rest of the current iteration, not the complete loop.
  • Use clear conditions so readers can understand why an item is being ignored.

Further Reading

Continue learning with these related Python tutorials:

Continue learning