class ExitLoops(Exception): pass try: for i in range(100): for j in range(100): for k in range(100): if i+j+k == 123: raise ExitLoops except ExitLoops: pass