while Loops
Rustom Mody
rustompmody at gmail.com
Wed Jun 22 00:04:44 EDT 2016
On Wednesday, June 22, 2016 at 9:20:35 AM UTC+5:30, 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?
>
Not sure what your question is
But I guess you are being tripped up by a pervasive and confusing pun
which you are inadvertently(?) using in one line:
a> i = i+1
b> 4+1 = 5
a> is an assignment statement IN the programming language python
b> is a math statement ABOUT python
a> in math is meaningless (unless i is ∞ or something)
b> in programming is a syntax error
If you feel you are confused thats good; most professional programmers are
more confused and dont know it.
The predecessor of python -- ABC -- wrote
i = i+1
as
PUT i+1 IN i
Unfortunately python followed the mainstream and confusified it to
i=i+1
More information about the Python-list
mailing list