Created
January 2, 2017 17:11
-
-
Save RatulSaha/28f8be2e03f16ae67afea04015d3aba7 to your computer and use it in GitHub Desktop.
Useful Loop tricks in Python
This file contains hidden or 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
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