How do I stop the infinite while loop by pushing a button | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How do I stop the infinite while loop by pushing a button

I tried using if function that contains break but it didn't work, in this code all 3 diodes are lighted and shut down periodically until i stop the simulation. https://code.sololearn.com/cXIHwaG5bV7Q/?ref=app

28th Nov 2020, 9:04 PM
Nemanja Boskovic
Nemanja Boskovic - avatar
2 Answers
+ 3
I am not familiar with your system but will hazard a theory which may help. Set up your pushbutton with a normally closed contact so it will generate a True input. while True: code goes here When you depress your button, you will break the while loop
28th Nov 2020, 9:45 PM
Rik Wittkopp
Rik Wittkopp - avatar
+ 1
Rik Wittkopp if i put it to normally generate a True input that will remove it's main purpose which is turning the loop on by clicking the button and generating that True input, thanks a lot for trying tho dude
28th Nov 2020, 9:58 PM
Nemanja Boskovic
Nemanja Boskovic - avatar