Skip to content

Instantly share code, notes, and snippets.

@j-nordell
Last active November 6, 2017 13:58
Show Gist options
  • Save j-nordell/7c6ae4aed673760e3defb61445d79cf8 to your computer and use it in GitHub Desktop.
Save j-nordell/7c6ae4aed673760e3defb61445d79cf8 to your computer and use it in GitHub Desktop.
Review break statements (for loop example)
cookie_jar = ["chocolate chip", "oatmeal raisin", "ginger",
"peanut butter", "sugar", "Oreo"] # I have these cookies in my cooke jar
for cookie in cookie_jar:
# (This may look complex, but don't worry about it right now.
# It just checks to see if we've tried half the cookies yet)
if cookie_jar.index(cookie) >= len(cookie_jar) / 2: # If we've already tasted half the cookies,
print("I've had enough cookies for today")
break # Call it quits for the day
print(f"The {cookie} cookie tastes delicious!") # Otherwise, take a bite!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment