Python Forum
break for loop - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: break for loop (/thread-25504.html)



break for loop - Agusben - Apr-01-2020

can i break a foor loop from outside the loop?


RE: break for loop - Larz60+ - Apr-01-2020

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