Solution: Skip Even Numbers
Explore how to use a Python for loop along with the continue statement to print all odd numbers from 1 to 10. Understand how the modulo operator helps identify even numbers, and apply control flow to skip them effectively in your program.
We'll cover the following...
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.