Asked • 04/16/19

How to do while loops with multiple conditions?

I have a while loop in python condition1=False condition1=False val = -1 while condition1==False and condition2==False and val==-1: val,something1,something2 = getstuff() if something1==10: condition1 = True if something2==20: condition2 = True ' ' I want to break out of the loop when all these conditions are true, the code above does not work I originally had while True: if condition1==True and condition2==True and val!=-1: break which works ok, is this the best way to do this? Thanks

2 Answers By Expert Tutors

By:

Joey G. answered • 04/18/20

Tutor
New to Wyzant

Howdy! My name is Joey and I am a Python Programmer from Wisconsin!

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.