break在while+else循环中的作用

# while + else 的应用(以及在break的影响下的运行的情况)
count = 0
while count < 11:
print(count)
count += 1
else:
print('输入')
# 此时的到的是 0到10的数 和 输入

count = 0
while count < 11:
if count == 7:
break
print(count)
count += 1
else:
print('输入')
# 此时得到的 是0到6的数字 却没有 输入 这俩个字
# 这说明了当while在没有被break主动结束的情况下,而是自动结束(也就是循环完成时)
# 会接着走下一段代码,也就是else代码
posted @ 2021-06-04 17:30  点滴180  阅读(191)  评论(0)    收藏  举报