Wait until any condition is True
Question:
I’m making a program in which I want it to stop and wait until any one of my condition is met. If one condition becomes True
while the other condition is still waiting, then the code will continue on with the True
condition. Sort of a mixture of if
, elif
, and while
statements.
Something like this:
until first_condition is False:
# wait
or until second_condition is False:
# wait
# continue the code
Answers:
You can use this:
while not(any([cond1, cond2])):
# Do something
Where the while loop will run until any conditions in the list are True.
For a simpler alternative (@ShadowRanger) when you have a smaller amount of conditions, you can use:
while not (cond1 or cond2 or cond3 or ...):
# Do something
I’m making a program in which I want it to stop and wait until any one of my condition is met. If one condition becomes True
while the other condition is still waiting, then the code will continue on with the True
condition. Sort of a mixture of if
, elif
, and while
statements.
Something like this:
until first_condition is False:
# wait
or until second_condition is False:
# wait
# continue the code
You can use this:
while not(any([cond1, cond2])):
# Do something
Where the while loop will run until any conditions in the list are True.
For a simpler alternative (@ShadowRanger) when you have a smaller amount of conditions, you can use:
while not (cond1 or cond2 or cond3 or ...):
# Do something