Skip to content

Instantly share code, notes, and snippets.

@pknowledge
Created September 7, 2018 01:10
Show Gist options
  • Save pknowledge/44f2a482901e91ab46fbe2d9615010be to your computer and use it in GitHub Desktop.
Save pknowledge/44f2a482901e91ab46fbe2d9615010be to your computer and use it in GitHub Desktop.
Python Tutorial for Beginners - break and continue
# 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