[Tutor] While Loop Question

George Fischhof george at fischhof.hu
Thu May 11 04:21:43 EDT 2017


2017-05-11 3:53 GMT+02:00 Rafael Skovron <rskovron at gmail.com>:

> Sorry I left out the indents in my previous email. It seems like j is
> always reset to zero. Why does j vary?
>
> Are there two different instances of j going on?
>
>
> for i in range(1, 5):
>
>     j=0
>
>    while j < i:
>
>          print(j, end = " ")
>
>          j += 1
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>



Hi,

As there is a j = 0 statement in the for cycle, it will be set to 0 every
time the while cycle finishes. (The while cycle will then increment j, then
if j == i j will be set to 0 again).

George


More information about the Tutor mailing list