簡述
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)