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
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