Skip to content

Instantly share code, notes, and snippets.

@RatulSaha
Created January 2, 2017 17:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RatulSaha/28f8be2e03f16ae67afea04015d3aba7 to your computer and use it in GitHub Desktop.
Save RatulSaha/28f8be2e03f16ae67afea04015d3aba7 to your computer and use it in GitHub Desktop.
Useful Loop tricks in Python
counter = 0
while counter <= 5:
print counter,
counter += 1
else:
print "loop exited normally"
# Output: 0 1 2 3 4 5 loop exited normally
for i in range(5):
print i,
if i > 3:
break
else:
print "loop exited normally"
# Output: 0 1 2 3 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment