Skip to content

Instantly share code, notes, and snippets.

@mattmess1221
Last active May 15, 2025 18:42
Show Gist options
  • Save mattmess1221/3b5c416a2aa75fd9d27c97b99229eafc to your computer and use it in GitHub Desktop.
Save mattmess1221/3b5c416a2aa75fd9d27c97b99229eafc to your computer and use it in GitHub Desktop.
class LabelBoundary(BaseException):
def __enter__(self):
return self
def __exit__(self, exc_type, exc_value, traceback):
return exc_value is self
def breakout(self):
raise self
with LabelBoundary() as label:
for x in [1, 2, 3]:
for y in [1, 2, 4, 5, 6]:
if y == 5:
raise label
print(x, y)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment