nested for loops

J

John Salerno

Can someone tell me why 'n' in this example isn't 2?
for x in range(2, n):
print 'x =', x, 'n =', n


x = 2 n = 3
 
C

Christoph Haas

Can someone tell me why 'n' in this example isn't 2?

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
 
J

Jesus Rivero - (Neurogeek)

It is, but range(2,2) doesn't do anything

Jesus Rivero - Neurogeek
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top