什么时候用for循环什么时候用while循环?

简述

for循环和while循环最大的区别在于【循环的工作量是否确定】,for循环就像空房间依次办理业务,直到把【所有工作做完】才下班。但while循环就像哨卡放行,【满足条件就一直工作】,直到不满足条件就关闭哨卡。for循环可以循环列表、字典、字符串、整数(range())。

 

实例说明

for循环

dict = {'日本':'东京','英国':'伦敦','法国':'巴黎'}

for i in dict:
  print(i)

while循环

a = 0
while a < 5:
    a = a + 1
    print(a)

posted on 2019-12-18 12:51  喝了少不如不喝  阅读(3506)  评论(0编辑  收藏  举报

导航