Skip to content

Instantly share code, notes, and snippets.

@jayeye
Created April 23, 2017 19:09
Show Gist options
  • Save jayeye/01eadaa8b679df6e52152ba02760d6cb to your computer and use it in GitHub Desktop.
Save jayeye/01eadaa8b679df6e52152ba02760d6cb to your computer and use it in GitHub Desktop.
Hacky way of breaking out of an inner loop. Definitely better than having a flag and testing it.
class _iloop(Exception):
pass
try:
for i in range(2, 10):
for j in range(2, 10):
if i == j * j:
raise _iloop
print(i, j)
except _iloop:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment