Break vs Continue Execution Difference
📖 Scenario: Imagine you are checking a list of daily temperatures to find if there is a very hot day or to skip cold days while counting warm days.
🎯 Goal: You will write Python code to see how break and continue change the flow inside a loop.
📋 What You'll Learn
Create a list called
temperatures with exact values: 22, 25, 30, 35, 28, 40, 20Create a variable called
hot_day_found and set it to FalseUse a
for loop with variable temp to go through temperaturesInside the loop, use
break to stop when temperature is 35 or moreCreate a variable called
warm_days_count and set it to 0Use a
for loop with variable temp to go through temperaturesInside the loop, use
continue to skip temperatures less than 25Increase
warm_days_count by 1 for each warm dayPrint the values of
hot_day_found and warm_days_count💡 Why This Matters
🌍 Real World
In real life, you might want to stop checking data once you find a critical value or skip irrelevant data points.
💼 Career
Understanding <code>break</code> and <code>continue</code> helps in writing efficient loops in data processing, automation, and many programming tasks.
Progress0 / 4 steps