
Hi I am learning Python. As a part of my learning process, I found your tutorial very helpful. Today I have found error in section 4.4. break<https://mail.google.com/mail/html/compose/reference/simple_stmts.html#break>and continue<https://mail.google.com/mail/html/compose/reference/simple_stmts.html#continue>Statements, and else<https://mail.google.com/mail/html/compose/reference/compound_stmts.html#else>Clauses on Loops
for n in range(2, 10):... for x in range(2, n):... if n % x == 0:... print n, 'equals', x, '*', n/x... break... else:... # loop fell through without finding a factor... print n, 'is a prime number'...2 is a prime number3 is a prime number4 equals 2 * 25 is a prime number6 equals 2 * 37 is a prime number8 equals 2 * 49 equals 3 * 3
The first output 2 is a prime number is not coming out I think when it goes in first inner for loop for x in range(2,2): range (2,2) is [] so it is not printing 2 is a prime number is not coming out I just want to make sure it my understanding is correct or there is mistake in document. Thanks -- Dhaval Patel

Hi Dhaval, thanks for your email. On Mon, Mar 28, 2011 at 01:15, Dhaval Patel <dh.electro@gmail.com> wrote:
do you mean this is not coming out when you're trying on your python shell? what version of python are you using?
I think when it goes in first inner for loop for x in range(2,2): range (2,2) is []
and that's correct, since it has to go into the 'else' branch.
The doc is correct: I tried several times and it works as expected, pay attention to the indentation of 'else' below the inner for loop. Don't hesitate to ask further in case it's not clear enough. Regards, -- Sandro Tosi (aka morph, morpheus, matrixhasu) My website: http://matrixhasu.altervista.org/ Me at Debian: http://wiki.debian.org/SandroTosi

Hi Dhaval, thanks for your email. On Mon, Mar 28, 2011 at 01:15, Dhaval Patel <dh.electro@gmail.com> wrote:
do you mean this is not coming out when you're trying on your python shell? what version of python are you using?
I think when it goes in first inner for loop for x in range(2,2): range (2,2) is []
and that's correct, since it has to go into the 'else' branch.
The doc is correct: I tried several times and it works as expected, pay attention to the indentation of 'else' below the inner for loop. Don't hesitate to ask further in case it's not clear enough. Regards, -- Sandro Tosi (aka morph, morpheus, matrixhasu) My website: http://matrixhasu.altervista.org/ Me at Debian: http://wiki.debian.org/SandroTosi
participants (2)
-
Dhaval Patel
-
Sandro Tosi