How to do while loops with multiple conditions(如何处理具有多个条件的WHILE循环)
问题描述
我在Python中有一个WHILE循环
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
'
'
当所有这些条件都为真时,我想退出循环,上面的代码不起作用
我原来有
while True:
if condition1==True and condition2==True and val!=-1:
break
哪种工作正常,这是执行此操作的最佳方法吗?
谢谢
推荐答案
将and
%s更改为or
%s。
这篇关于如何处理具有多个条件的WHILE循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!