nested for loops

Christoph Haas email at christoph-haas.de
Tue Mar 21 17:06:33 EST 2006


On Tue, Mar 21, 2006 at 09:54:21PM +0000, John Salerno wrote:
> Can someone tell me why 'n' in this example isn't 2?
> 
>  >>> for n in range(2, 10):
> 	for x in range(2, n):
> 		print 'x =', x, 'n =', n
> 
> 		
> x = 2 n = 3

Assume n=2. Then the first inner loop will run in a range(2,2) which is an
empty list. So nothing will happen.

Next outer loop: n=3...

Actually n becomes 2. But you don't do anything with it. :)

 Christoph
-- 
~
~
".signature" [Modified] 1 line --100%--                1,48         All



More information about the Python-list mailing list