[Tutor] Nested for loops

Dave Angel davea at davea.name
Wed Nov 27 22:33:01 CET 2013


On Wed, 27 Nov 2013 17:08:11 +0100, Rafael Knuth 
<rafael.knuth at gmail.com> wrote:
>     for x in range(2, n):
>         if n % x == 0:
>             print(n, 'equals', x, '*', n//x)




> #3 Round:
> n = 4
> x = 3

When n is 4, the inner loop will test 2, then 3.  But since n% x is 
zero for values 4 and 2, it will print,  then break.  Because of the 
break,  it won't even get to 3.

-- 
DaveA



More information about the Tutor mailing list