Editor settings

General settings

Save settings

Learn to program with Python

Skip a loop with continue #

The continue statement skips the current item and moves on to the next item in the loop. Unlike break, the loop will continue until all items have been processed.

In the example below, we see that only odd numbers are printed since the print statement is skipped when the number is even.

numbers = [1, 2, 3, 4, 5, 6, 7 ,8 ,9, 10]

for number in numbers:
    if number % 2 == 0:
        continue
    print(number)

print("This is called after the loop")

Here's the output of the example code above:

1
3
5
7
9
This is called after the loop

Exercise #

  • Use continue inside for loop so that only even numbers are printed to the output.
Output will be displayed here