关于break放置顺序的问题
为什么这样写
sum = 0
x = 1
n = 1
while True:
sum = sum + x
x = 2*x
n +=1
if n >20:
break
print sum
和这样写
sum = 0
x = 1
n = 1
while True:
if n >20:
break
sum = sum + x
x = 2*x
n +=1
print sum
得出的结果是一样的,第二种不应该少执行一次吗?
为什么这样写
sum = 0
x = 1
n = 1
while True:
sum = sum + x
x = 2*x
n +=1
if n >20:
break
print sum
和这样写
sum = 0
x = 1
n = 1
while True:
if n >20:
break
sum = sum + x
x = 2*x
n +=1
print sum
得出的结果是一样的,第二种不应该少执行一次吗?
2017-01-21
举报