1-3-05 语句-循环语句-while else --了解

当while后的条件不成立时,else中的代码就会执行。

while 条件:
  代码
else:
  代码
while False:
  passelse:
  print(123)
num = 1while num < 5:
  print(num)
  num = num + 1else:
  print(666)

# 输出 1234666
while True:
  print(123)
        breakelse:
  print(666)

# 输出123
posted @ 2022-10-18 22:24  布丁家的苏苏  Views(11)  Comments(0)    收藏  举报