pythonfor-loopscopenestedcontinue

What Is The Scope Of Continue In A Nested Python For Loop?


When using nested for loops, if I use continue inside the inner nested for loop, does the scope of that continue only apply to the inner loop or will it continue the outer loop?

Note: For what I am working on I only want the continue to affect the nested loop

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

Solution

  • It only affects the inner loop.