while和for循环的区别


1、循环的次数确定使用for循环语句

a = [1, 2, 3, 4, 5, 6, 7, 8, 9]
for x in a:
    print(x)

2、循环的次数不确定使用while循环语句

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

results matching ""

    No results matching ""