Looping [was Re: Python and the need for speed]
Christian Gollwitzer
auriocus at gmx.de
Tue Apr 18 02:06:49 EDT 2017
Am 18.04.17 um 02:18 schrieb Ben Bacarisse:
> Thanks (and to Grant). IO seems to be the canonical example. Where
> some languages would force one to write
>
> c = sys.stdin.read(1)
> while c == ' ':
> c = sys.stdin.read(1)
>
> Python opts for
>
> while True:
> c = sys.stdin.read(1)
> if c != ' ': break
This loop would be the archetypical do..while or repeat...until to me.
do
c = sys.stdin.read(1)
while c== ' '
-or-
repeat
c = sys.stdin.read(1)
until c != ' '
is the most clear to me - and in fact this "while True; do something;
break" thingy is just an idiom to fake a do..while loop in Python.
C does have it, for example, and it is way better like this than the
abuse of assignment and comma operator in the condition.
Christian
More information about the Python-list
mailing list