很多次我都在编写3或4个嵌套循环,问题是使用break语句,我只能跳过其中的一个循环,其余的循环将继续进行。
是否存在破坏所有嵌套循环的情况?
例:
a = 3
b = 4
c = 5
while a <= 333:
b = a + 1
while b <= 500:
c = 1000 - a - b
while c < 500:
if c**2 == (a**2) + (b**2) and a + b + c = 1000:
print("this is the first number : ", a)
print("this is the second number : " ,b)
print("and this is the third number : " ,c)
break
else :
c +=1
b +=1
a +=1
print(a)这是我为Euler #9项目编写的代码!
如果满足if语句的条件..。我怎样才能阻止那些循环运行呢?
发布于 2016-07-29 18:36:43
尝试创建一个函数,并使用return语句。
发布于 2016-07-29 18:37:05
在python中没有一种使用一个break语句来突破嵌套循环的方法。
https://stackoverflow.com/questions/38665449
复制相似问题