while Loops

Wildman best_lay at yahoo.com
Wed Jun 22 00:04:23 EDT 2016


On Tue, 21 Jun 2016 20:50:24 -0700, Elizabeth Weiss wrote:

> i=1
> while i<=5:
>    print(i)
>    i=i+1
> 
> The result is:
> 1
> 2
> 3
> 4
> 5
> 
> Why is one of the results 5 since i=i+1? Should the maximum result be 4 since 4 +1=5? 
> 
> Thanks for your help!

The operator '<=' means less than or equal.  To get the results
you are expecting, you need to use '<' only.

i=1
while i<5:
    print(i)
    i=i+1

1
2
3
4

-- 
<Wildman> GNU/Linux user #557453
The cow died so I don't need your bull!


More information about the Python-list mailing list