Python 在两个环路外断开
我正在编写一个代码,在while循环中包含一个while循环,我想知道如果我在内部循环中满足必要的条件,如何打破外部循环Python 在两个环路外断开,python,while-loop,break,Python,While Loop,Break,我正在编写一个代码,在while循环中包含一个while循环,我想知道如果我在内部循环中满足必要的条件,如何打破外部循环 while N <= 8: while i < 60: if this: that elif this: that other thing else: break i += 1 if while loop has
while N <= 8:
while i < 60:
if this:
that
elif this:
that other thing
else:
break
i += 1
if while loop has found the right thing:
N += 1
else:
change conditions
whilen将其封装在函数中并在完成时返回?将其封装在函数中并在完成时返回?使用标志
:
flag = True
while N <= 8:
while i < 60:
if this:
that
elif this:
that other thing
else:
flag = False # To exit from outer while loop
break
i += 1
if(not flag):
break # Condition in inner loop is met
if while loop has found the right thing:
N += 1
else:
change conditions
flag=True
当N使用标志时
:
flag = True
while N <= 8:
while i < 60:
if this:
that
elif this:
that other thing
else:
flag = False # To exit from outer while loop
break
i += 1
if(not flag):
break # Condition in inner loop is met
if while loop has found the right thing:
N += 1
else:
change conditions
flag=True
而N使用标志<此处使用代码>触发器
trigger = False
while N <= 8:
while i < 60:
if this:
that
elif this:
that other thing
else:
trigger = True
break
i += 1
if trigger:
break
elif while loop has found the right thing:
N += 1
else:
change conditions
trigger=False
而N使用标志<此处使用代码>触发器
trigger = False
while N <= 8:
while i < 60:
if this:
that
elif this:
that other thing
else:
trigger = True
break
i += 1
if trigger:
break
elif while loop has found the right thing:
N += 1
else:
change conditions
trigger=False
while N设置一个在内部循环后检查的变量?引发异常并将顶部while循环放入try/except块?break
仅从最小的封闭循环中中断。您希望在代码中的哪个位置从外部循环中断?设置一个在内部循环之后检查的变量?引发异常并将顶部while循环放入try/except块?break
仅从最小的封闭循环中断。您希望在代码中的哪个位置断开外部循环?检查中的true/false
或true/false
Python@DineshPanchananam我试图解释标志的概念,它不是特定于一种语言的。无论如何,谢谢你的提醒,我会纠正它。在内环的中断
之后,标志为False,它永远不会运行外环的中断。我认为第二个条件是if not flag
。另外,您的想法很好,请检查中的true/false
或true/false
Python@DineshPanchananam我试图解释标志的概念,它不是特定于一种语言的。无论如何,谢谢你的提醒,我会纠正它。在内环的中断
之后,标志为False,它永远不会运行外环的中断。我认为第二个条件是if not flag
。嗯,你的想法很好