Looping [was Re: Python and the need for speed]

Chris Angelico rosuav at gmail.com
Tue Apr 18 02:21:19 EDT 2017


On Tue, Apr 18, 2017 at 4:06 PM, Christian Gollwitzer <auriocus at gmx.de> wrote:
> 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 != ' '

Except that there's processing code after it.

while True:
    c = sys.stdin.read(1)
    if not c: break
    if c.isprintable(): text += c
    elif c == "\x08": text = text[:-1]
    # etc

Can you write _that_ as a do-while?

ChrisA



More information about the Python-list mailing list