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
Asked By: ابن آدم

||

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
Answered By: Freddy Mcloughlan
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.