New submission from Pradnyan <paraak...@gmail.com>:

I have come across very strange Python bug in nested for loops:
See below nested for loop with range function and its not working as expected.

It worked fine until cnt=2136 and start giving unexpected output after that. 

As per logic y value should get incremented for every x value but after 
cnt=2136 the y value remains 0 and x gets incremented and also
code did not stop for cnt>2137 and it halts only at 5352.

I have attached actual python code and its output. This code is executed on 
latest python build 3.7.3

Erroneous output 
================================================================
cnt=2134 y=2133 x=0
cnt=2135 y=2134 x=0
cnt=2136 y=2135 x=0
cnt=2137 y=0 x=1
cnt=2138 y=1 x=1
cnt=2139 y=0 x=2
cnt=2140 y=0 x=3
cnt=2141 y=0 x=4

==================================================================
==================================================================
Python code:
==================================================================
 cnt=0
    for x in range(3216):
        for y in range(2136):
            cnt = cnt + 1
            #print("y="+str(y)+" x="+str(x)+" pixel="+str(im_ary[y,x]))
            print("cnt="+str(cnt)+" y=" + str(y) + " x=" + str(x) )
            if cnt>2137 :
                break

=================================================================

----------
components: Build
files: Pyton_For_Loop_issue.zip
messages: 346884
nosy: anthonybaxter, barry, benjamin.peterson, eric.araujo, ezio.melotti, 
georg.brandl, gvanrossum, lemburg, mdk, ned.deily, pradnyan, tarek
priority: normal
severity: normal
status: open
title: Nested For Loop in Python not working as Expected after cnt=2136
type: behavior
versions: Python 3.7
Added file: https://bugs.python.org/file48444/Pyton_For_Loop_issue.zip

_______________________________________
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