while 循环和else

while 循环中,只要没被break打断,循环会执行完循环体内所以的内容

count = True
while count:
    print(1)
    count = False
    print(2)
运行结果:1
        2

while循环与else组合使用,循环中如果被break打断,则slse不会执行

count = 0
while count < 5:
    count += 1
    if count == 5:
        break
else:
    print(7)
运行结果不会打印7

  

posted @ 2022-07-22 11:24  401561993  阅读(65)  评论(0编辑  收藏  举报