0
0
Pythonprogramming~15 mins

Continue statement behavior in Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Continue Statement Behavior
📖 Scenario: Imagine you are sorting a list of numbers and want to skip printing any number that is even. You will use the continue statement to skip those numbers and only print the odd ones.
🎯 Goal: Build a small program that loops through a list of numbers, uses the continue statement to skip even numbers, and prints only the odd numbers.
📋 What You'll Learn
Create a list called numbers with the exact values: [1, 2, 3, 4, 5, 6]
Create a variable called count and set it to 0
Use a for loop with the variable num to iterate over numbers
Inside the loop, use an if statement to check if num is even and use continue to skip printing it
Print each odd number inside the loop
After the loop, print the total count of odd numbers printed
💡 Why This Matters
🌍 Real World
Skipping unwanted items in a list is common when filtering data, like ignoring certain records or values in real applications.
💼 Career
Understanding how to control loops with continue helps in writing efficient code for data processing, automation, and many programming tasks.
Progress0 / 4 steps
1
Create the list of numbers
Create a list called numbers with these exact values: [1, 2, 3, 4, 5, 6]
Python
Need a hint?

Use square brackets to create a list and separate numbers with commas.

2
Create a counter variable
Create a variable called count and set it to 0 to keep track of how many odd numbers are printed
Python
Need a hint?

Just write count = 0 on a new line.

3
Loop and use continue to skip even numbers
Use a for loop with the variable num to iterate over numbers. Inside the loop, use an if statement to check if num % 2 == 0 (even number) and use continue to skip printing it. For odd numbers, increase count by 1 and print num.
Python
Need a hint?

Use for num in numbers: to loop. Use if num % 2 == 0: to check even numbers. Use continue to skip them.

4
Print the total count of odd numbers
After the loop, write print(f"Total odd numbers: {count}") to display how many odd numbers were printed
Python
Need a hint?

Use an f-string to print the count variable after the loop.