首页 > 代码库 > while循环

while循环

例(1)
count_1 = True
while count_1:
    print(1)
    print(2)
    count_1 = False
print(3)

例(2)
count_1 = True
while count_1:
    print(1)
    print(2)
    count_1 = False
print(3)

例(3)
count_1 = 1
count_2 = True
while count_2:
    print(count_1)
    if count_1 == 100:
        count_2 = False
    count_1 +=1
print(end.....)


例(4)
count_1 = 1
while count_1:
    print(count_1)
    if count_1 == 100:
        break #跳出当前循环
    count_1 +=1
print(end.....)

例(5while True:
    print(123)
    continue#结束本次循环跳到下一次循环
    pritn(456)
print(end.....)

例(3)
count_1 = 0
while True:
    if count_1 == 6 or count_1 == 3:
        count_1 += 1
        continue
    print(count_1)
    count_1 += 1
    if count_1 == 10:
        break
print(‘end.....‘)

  

 

while循环