while else
程序员文章站
2022-07-06 23:18:28
结果: Loop 1Loop 2Loop 3Loop 4Loop 5Loop 6循环执行完啦 out of while loop Loop 1Loop 2 out of while loop 结论:while循环正常执行完不会执行else里边的代码,如果while循环被break中断则会执行else ......
1 count = 0 2 while count <= 5 : 3 count += 1 4 if count == 3:pass 5 print("loop",count) 6 7 else: 8 print("循环执行完啦") 9 print("-----out of while loop ------")
结果:
loop 1
loop 2
loop 3
loop 4
loop 5
loop 6
循环执行完啦
-----out of while loop ------
1 count = 0 2 while count <= 5 : 3 count += 1 4 if count == 3:break 5 print("loop",count) 6 7 else: 8 print("循环执行完啦") 9 print("-----out of while loop ------")
loop 1
loop 2
-----out of while loop ------
结论:while循环正常执行完不会执行else里边的代码,如果while循环被break中断则会执行else里边的代码
上一篇: s21day11 python笔记
下一篇: 陋室铭搞笑姐妹篇