Created
September 7, 2018 01:10
-
-
Save pknowledge/44f2a482901e91ab46fbe2d9615010be to your computer and use it in GitHub Desktop.
Python Tutorial for Beginners - 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
# Python Tutorial for Beginners - break and continue | |
a = [0, 1, 2, 3, 4, 5] | |
print('-----------break for loop---------------------') | |
for x in a: | |
if x == 2: | |
break | |
print(x) | |
print('-----------continue for loop---------------------') | |
for x in a: | |
if x == 2: | |
continue | |
print(x) | |
print('-----------break while loop---------------------') | |
i = 0 | |
while i < 5: | |
i += 1 | |
if i == 3: | |
break | |
print(i) | |
j = 0 | |
print('-----------continue while loop---------------------') | |
while j < 5: | |
j += 1 | |
if j == 2: | |
continue | |
print(j) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment