Files
Learn-Python-Programming-Th…/ch07/exceptions/for.loop.py
T
adii1823 32c12d89f4 ch07
2021-10-28 17:39:13 +05:30

26 lines
592 B
Python

# exceptions/for.loop.py
n = 100
found = False
for a in range(n):
if found: break
for b in range(n):
if found: break
for c in range(n):
if 42 * a + 17 * b + c == 5096:
found = True
print(a, b, c) # 79 99 95
class ExitLoopException(Exception):
pass
try:
n = 100
for a in range(n):
for b in range(n):
for c in range(n):
if 42 * a + 17 * b + c == 5096:
raise ExitLoopException(a, b, c)
except ExitLoopException as ele:
print(ele.args) # (79, 99, 95)