Skip to content

Instantly share code, notes, and snippets.

@plavjanik
Created June 16, 2022 09:29
Show Gist options
  • Save plavjanik/96eb9a19f5fd88232edeb4c3320221d5 to your computer and use it in GitHub Desktop.
Save plavjanik/96eb9a19f5fd88232edeb4c3320221d5 to your computer and use it in GitHub Desktop.
Distinguishing multiple exit points in loops
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