Python continue语句

Python continue语句:

当执行到 continue 语句时,将不再执行本次循环中 continue 语句接下来的部分,而是继续下一次循环。

lst = [7,8,9,4,5,6]

for i in range(len(lst)):
    if lst[i] == 9:
        continue
#当运行到 continue 语句时,不执行本次循环中剩余的代码,而是继续下一层循环
    print(lst[i],end = "  ")
# 7  8  4  5  6

当存在嵌套循环时:

lst = [7,8,9,4,5,6]
for i in range(2):
    for j in range(len(lst)):
        if lst[j] == 4:
            continue  # 跳出本次循环,进入下一层循环
        print(lst[j], end="  ")
    print()
# 7  8  9  5  6  
# 7  8  9  5  6  

2020-02-06

原文地址:https://www.cnblogs.com/hany-postq473111315/p/12268306.html