Answer the question
In order to leave comments, you need to log in
How to forcibly block the execution of the while loop and all the loops that are inside it?
while turned_on:
sub_loop
How, when the variable turned_on is changed to True, block the execution of the while loop and all previously running loops inside it without waiting for the code to complete execution.
Answer the question
In order to leave comments, you need to log in
For example with exceptions:
class BreakIt(Exception): pass
try:
for x in range(10):
for y in range(10):
print x*y
if x*y > 50:
raise BreakIt
except BreakIt:
pass
Put the outer while in the function; do a return to stop all loops.
Controlling execution through an exception is also valid in Python, but return is more readable.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question