![](https://secure.gravatar.com/avatar/e7aa69343878d1aae09ef9d6100ec8bf.jpg?s=120&d=mm&r=g)
Hi, In section 4.4 break and continue Statements and else Clauses in loops, the first program has an issue: the second for: for x in range(2,n) is not entered in the first iteration of the n for (for n in range(2,10)) as range (2,2) give an empty range:
range(2,2) []
therefore 2 is never "declared" prime. Also the break is in the wrong place. bm
![](https://secure.gravatar.com/avatar/e7aa69343878d1aae09ef9d6100ec8bf.jpg?s=120&d=mm&r=g)
and of course there are some test missing as whatever is not even is first declared prime. bm On Fri, Jul 5, 2013 at 8:26 AM, Blanca Mancilla <blancalmancilla@gmail.com>wrote:
Hi, In section 4.4 break and continue Statements and else Clauses in loops, the first program has an issue: the second for: for x in range(2,n) is not entered in the first iteration of the n for (for n in range(2,10)) as range (2,2) give an empty range:
range(2,2) []
therefore 2 is never "declared" prime.
Also the break is in the wrong place.
bm
![](https://secure.gravatar.com/avatar/3c46e59585526b90c088845402bc8407.jpg?s=120&d=mm&r=g)
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Am 05.07.2013 14:26, schrieb Blanca Mancilla:
Hi, In section 4.4 break and continue Statements and else Clauses in loops, the first program has an issue: the second for: for x in range(2,n) is not entered in the first iteration of the n for (for n in range(2,10)) as range (2,2) give an empty range:
range(2,2) []
therefore 2 is never "declared" prime.
Also the break is in the wrong place.
Hi Blanca, if you look closely at the source, the "else" clause belongs to the "for" loop. If you indent the clause correctly, the code will work as expected. cheers, Georg -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.21 (GNU/Linux) iEYEARECAAYFAlJRLMoACgkQN9GcIYhpnLDrFwCdFAF2SlbI5weQCU0AVFhg0W9i 9uwAnj0FZOVu1Yso6Y7vxqBsiVRVPquX =ew97 -----END PGP SIGNATURE-----
participants (2)
-
Blanca Mancilla
-
Georg Brandl