Last active
September 20, 2018 03:01
-
-
Save zlargon/2bffded52a464ef5977755a277751e5e to your computer and use it in GitHub Desktop.
python break and continue
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
# example 1: print 1 2 3 4 5 | |
i = 1 | |
while i < 6: | |
print(i) | |
i += 1 |
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
# example 2: print 1 2 3 | |
i = 1 | |
while i < 6: | |
# stop and jump out while loop | |
if i == 4: | |
print("break") # for debug | |
break | |
print(i) | |
i += 1 |
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
# example 3: print 1 2 5 | |
i = 1 | |
while i < 6: | |
# skip 3 and 4 | |
if i == 3 or i == 4: | |
i += 1 | |
print("continue") # for debug | |
continue | |
print(i) | |
i += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment