为什么while语句中嵌套的if语句,条件符合第二个if,却还是执行第一个表达式呢?
浏览:955 回答:1
for i in range(4): j=i while j<3: if j>= 2: print 'break here i ='+str(i) break else : j +=1 else: print"no break occur!\nj = " + str(j) print'in for expr: i ='+str(i) print ' end of programm'
输出结果: # break here i =0 # in for expr: i =0 # break here i =1 # in for expr: i =1 # break here i =2 # in for expr: i =2 # no break occur! # j = 3 # in for expr: i =3
我的疑问是当j=0,1,时候,满足while 但是不满足if J>=2
为什么输出的时候执行了
print'break here i ='+str(i)
得到了
break here i =0 # in for expr: i =0 # break here i =1 # in for expr: i =1