Home > Software design >  While loop only takes one condition
While loop only takes one condition

Time:11-06

The while loop command only takes one condition or it'll ignore them entirely. The script ends up running the program infinitely.

You can clearly see that the loop doesn't stop even with blue = True

same thing here

I've tried running the keyboard condition as a variable. I've also tried a variable counter (while i < 4) as one of the conditions with the same results. Switching the conditions and putting them in parenthesis didn't work either.

Is there any way to solve this issue?

Thank you in advance!

CodePudding user response:

If one of the 2 conditions is true then it keeps on looping.

In order to exit the loop both conditions MUST be false. Meaning :

  • blue must be true
  • q must be pressed

Don't know pyautogui and its is_pressed() behaviour. May be you've to keep the finger on the q key to satisfy the 2nd condition ?

  • Related