Solution: Skip Even Numbers
We'll cover the following...
This program prints all odd numbers from 1 to 10 using a for loop and the continue statement.
range(1, 11)generates numbers from 1 to 10 (the end value 11 is not included).The
if number % 2 == 0line checks if a number is even using the modulo operator%.%gives the remainder after division.If the remainder is
0when dividing by2, the number is even.
continuetells Python to skip the rest of the loop for that number and move to the next one.So, only odd numbers (those not skipped) get printed.
Python
for number in range(1, 11):if number % 2 == 0:continueprint(number)