[Tutor] while statement

Emil Styrke emil@lysator.liu.se
Thu May 1 06:27:02 2003


Mic Forster <micforster@yahoo.com> writes:

> Thanks Sean,
>
> that's actually what I had written and my mistake was
> in the equation. Missed a bracket here and there but
> she's sweet now. Thanks for the assistance. Mic
>

Another method is the for loop, it will save you the manual
incrementing of n:

for n in range(1, N+1):
    do_stuff

range(x, y) creates a list with the integer elements i, where x <= i < y,
and the for loop will iterate through each element in this list,
assigning the current element to n.

          /Emil

>
> --- Sean 'Shaleh' Perry <shalehperry@attbi.com> wrote:
>> > and this is repeated until n = N.
>> >
>> > I know that the while statement needs to be used
>> but I
>> > am unsure of the exact syntax. I am having
>> problems
>> > incrementing n by 1 in each iteration.
>> >
>> 
>> while n != N: # or maybe n < N
>>    do_stuff
>>    n = n + 1 # or with newer (2.2+) n += 1
>> 
>> _______________________________________________
>> Tutor maillist  -  Tutor@python.org
>> http://mail.python.org/mailman/listinfo/tutor
>
>
> __________________________________
> Do you Yahoo!?
> The New Yahoo! Search - Faster. Easier. Bingo.
> http://search.yahoo.com
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor