while-else

python学习网 2018-12-17 11:38:02

while-else

1、break立即打断循环并且不再执行else

count = 0
while count <= 5:
    count += 1
    if count == 3:
        break
    print("loop",count)
else:
    print("循环执行完了")
print("end")

 

2、while循环后会执行else

count = 0
while count <= 5:
    count += 1
    if count == 3:
        pass
    print("loop",count)
else:
    print("循环执行完了")
print("end")

 

 

阅读(8660) 评论(0)