Basic question

Basilisk96 basilisk96 at gmail.com
Sat May 12 13:45:33 EDT 2007


On May 12, 12:18 pm, "Cesar G. Miguel" <cesar.go... at gmail.com> wrote:
> I've been studying python for 2 weeks now and got stucked in the
> following problem:
>
> for j in range(10):
>   print j
>   if(True):
>        j=j+2
>        print 'interno',j
>
> What happens is that "j=j+2" inside IF does not change the loop
> counter ("j") as it would in C or Java, for example.
>
> Am I missing something?
>
> []'s
> Cesar

What is your real intent here? This is how I understand it after
reading your post: you want to create a loop that steps by an
increment of 2. If that's the case, then:

>>> for j in range(0,10,2):
...     print j
...
0
2
4
6
8

would be a simple result.

Cheers,
-Basilisk96




More information about the Python-list mailing list