Continue Statement in Python

Level 254 keystrokes

Loops from 1 to 5 and uses continue to skip the even numbers, printing only the odd ones.

Python code

1for n in range(1, 6):
# continue jumps straight to the next iteration when n is even
2 if n % 2 == 0:
3 continue
# Only odd numbers reach this line: 1, 3, 5
4 print(n)

Output

1
3
5
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this Python code and how often they appear.

  • :× 2
  • (× 2
  • )× 2
  • =× 2
  • ,× 1
  • %× 1

More Python examples at level 2

← Python typing practice