Skip to content

Instantly share code, notes, and snippets.

@zlargon
Last active September 20, 2018 03:01
Show Gist options
  • Save zlargon/2bffded52a464ef5977755a277751e5e to your computer and use it in GitHub Desktop.
Save zlargon/2bffded52a464ef5977755a277751e5e to your computer and use it in GitHub Desktop.
python break and continue
# example 1: print 1 2 3 4 5
i = 1
while i < 6:
print(i)
i += 1
# 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
# 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