Karthikeyan Singaravelan <tir.kar...@gmail.com> added the comment:

@pradnyan The break statement [0] only exits the for loop where it's present in 
this the one where y is involved so the outer loop involving x will continue to 
execute. So after every attempt where y = 0 the cnt value succeeds and breaks 
out of the loop. I think this is a problem with the logic that you want to 
refactor and not a problem with CPython.

def test():
    cnt=0
    for x in range(3216):
        for y in range(2136):
            cnt = cnt + 1
            print("cnt="+str(cnt)+" y=" + str(y) + " x=" + str(x) )
            if cnt > 2137 : 
                break # Break only out of "for y in in range(2136)"

In future reports please also don't add many people to the nosy list.

[0] 
https://docs.python.org/3/tutorial/controlflow.html#break-and-continue-statements-and-else-clauses-on-loops

----------
nosy: +xtreak
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue37447>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to