Created
June 16, 2022 09:29
-
-
Save plavjanik/96eb9a19f5fd88232edeb4c3320221d5 to your computer and use it in GitHub Desktop.
Distinguishing multiple exit points in loops
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
colors = ["red", "green", "blue", "orange"] | |
# ❌ | |
found = False | |
for color in colors: | |
if color == "orange": | |
found = True | |
break | |
if not found: | |
print("Orange not found") | |
else: | |
print("🟠") | |
# ✔️ | |
for color in colors: | |
if color == "orange": | |
print("🟠") | |
break | |
else: | |
print("Orange not found") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment