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 0Use a
for loop with the variable num to iterate over numbersInside the loop, use an
if statement to check if num is even and use continue to skip printing itPrint 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