Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 946
Michael Crowley Avatar asked Oct 30 '25 03:10

Michael Crowley


1 Answers

It only affects the inner loop.

like image 198
botiapa Avatar answered Oct 31 '25 17:10

botiapa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!