26 lines
592 B
Python
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)
|