循环中使用break语句


1、break语句用于结束整个循环

2、break语句用于while循环或for循环

3、for循环中使用break

a = [1, 2, 3, 4, 5, 6]
for x in a:
    if x == 4:
        break
    print(x)

4、while循环中使用break

a = 0
while a < 6:
    a += 1
    if a == 4:
        break
    print(a)

results matching ""

    No results matching ""