Python Forum

Full Version: break for loop
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
can i break a foor loop from outside the loop?
You can set a condition (outside of the loop) that is looked at inside of the loop, and break if set
You will probably have to use threads in order to get them to play together
example:
# in init:
breaker = False
# in one thread:
myloop:
   ...
   if breaker:
       breaker = False
       break
   ...
# in another thread, when you want loop to break:
breaker = True