Nested For and While Statements

Zentrader zentraders at
Mon Sep 24 22:10:44 CEST 2007

> Your for loops both use the same counting index.

Since those variables are local to the for loop, theoretically it
should work with both loops using the same variable.  Although bad
practice, I tested it on my machine and the following code does indeed
work as expected, so it appears that the problem is indenting the for
loops properly.
for j in range( 10 ):
   print j, "first loop"
   for j in range( 5 ):
      print "     ", j, "2nd loop"

More information about the Python-list mailing list