Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- import contextlib
- @contextlib.contextmanager
- def Label(name):
- class _Label(Exception):
- pass
- try:
- yield _Label
- except _Label:
- print("loop break:", name)
- with Label("label1") as label1:
- for x in range(5):
- print("L1", x)
- with Label("label2") as label2:
- for y in range(10, 50, 10):
- print("L2", y)
- for z in range(100, 500, 100):
- print("L3", z)
- if x > 1:
- raise label1()
- if y > 10:
- raise label2()
- if z > 200:
- print("loop break: L3")
- break
Advertisement
Add Comment
Please, Sign In to add comment