小编Mic*_*ley的帖子

嵌套 Python For 循环中 continue 的范围是什么?

使用嵌套 for 循环时,如果我在内部嵌套 for 循环中使用 continue,则 continue 的范围仅适用于内部循环还是会继续外部循环?

注意:对于我正在做的事情,我只想继续影响嵌套循环

b = ["hello"] * 5
d = ["world"] * 10

for a in b: # Outer Loop
    x = 1 + 1
    for c in d: # Nested Loop
        if c:
            x += 1
        else: 
            continue # Does this affect the Nested Loop or the Outer Loop
Run Code Online (Sandbox Code Playgroud)

python scope for-loop nested continue

3
推荐指数
1
解决办法
2325
查看次数

标签 统计

continue ×1

for-loop ×1

nested ×1

python ×1

scope ×1