Nested loops confusion

Matthew Graham nospam at nospam.net
Thu May 11 00:51:05 EDT 2006


Hi,

I expect this is very obvious for anyone who knows what they're doing - 
but I don't understand what's the problem with the following code.  I 
was intending that the program cycle through all i and j (ie. all 
possible (i,j) coordinates, but the output when I run the program shows 
me up to

"1
99
plot 3
1
100
plot 2
done j"

and doesn't perform the print functions for any i > 1.

Help much appreciated! :)

Matt


corna = int(raw_input("CornA? "))
cornb = int(raw_input("CornB? "))
side = int(raw_input("Side? "))
i = 0
j = 0
for i in range(100):
     for j in range(100):
             x = corna + i * side / 100
             y = cornb + j * side / 100
             c = int(x^2 + y^2)
             if  c%3 == 1:
                 print i
                 print j
                 print "plot 1"
             elif  c%3 == 2:
                 print i
                 print j
                 print "plot 2"
             elif  c%3 == 0:
                 print i
                 print j
                 print "plot 3"
     print "done j"
print "Done i"





More information about the Python-list mailing list