python – while/for

2023-04-12 20:53:05 浏览数 (1)

循环控制语句

1.break,跳出循环 2.continue,跳过本次循环

while

代码语言:javascript复制
i = 0

while 1 >= 100:

    if i >= 10:
        print("while循环结束")
        result = False
    else:
        i  = 1
        print(f"while循环 - {i}")

for

代码语言:javascript复制
for i in range(1,100):

    if i <= 10:

        if i % 2 == 0:
            print(f"for循环 - {i}")
        else:
            print(f"for循环 - {i} - 非偶数,已跳过~")
        continue
    else:
        print("跳出循环")
        break

0 人点赞