Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
break for loop
#1
can i break a foor loop from outside the loop?
Reply
#2
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Break within an if statement inside a while loop not working Python_more_on 2 1,893 Sep-03-2025, 12:55 AM
Last Post: Pedroski55
  Code won't break While loop or go back to the input? MrKnd94 2 2,806 Oct-26-2022, 10:10 AM
Last Post: Larz60+
  How to break out of a for loop on button press? philipbergwerf 6 4,724 Oct-06-2022, 03:12 PM
Last Post: philipbergwerf
  break out of for loop? User3000 3 3,286 May-17-2022, 10:18 AM
Last Post: User3000
  Asyncio: Queue consumer gets out of while loop without break. Where exactly and how? saavedra29 2 5,762 Feb-07-2022, 07:24 PM
Last Post: saavedra29
  tkinter control break a while loop samtal 0 3,672 Apr-29-2021, 08:26 AM
Last Post: samtal
  Cannot 'break' from a "for" loop in a right place tester_V 9 6,606 Feb-17-2021, 01:03 AM
Last Post: tester_V
  How to break a loop in this case? Blainexi 10 11,679 Sep-24-2020, 04:06 PM
Last Post: Blainexi
  how to break the loop? bntayfur 8 5,523 Jun-07-2020, 11:07 PM
Last Post: bntayfur
  Help For AutoGui Loop break ahmetnwpal 0 3,016 Mar-11-2020, 01:14 PM
Last Post: ahmetnwpal

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020