seeking deeper (language theory) reason behind Python design choice
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Fri May 11 01:45:27 EDT 2018
On Fri, 11 May 2018 01:51:47 +0300, Marko Rauhamaa wrote:
> Paul Rubin <no.email at nospam.invalid>:
>
>> Marko Rauhamaa <marko at pacujo.net> writes:
>>> It turns out "while True" is the most natural choice in about half of
>>> the while loops.
>>
>> Maybe the rest would be "repeat until" if Python had that?
>
> No. "Repeat until" is a relatively infrequent need.
And again, YMMV. In my experience, most "while True" loops would be
better off written as a "repeat... until True" loop. But since Python
doesn't have syntax for such repeat until loops, our work-around is to
use a while True and break out of it at the end of the loop.
To be honest, I'm having trouble thinking of a good use-case for "while
True", now that we have infinite iterators. Most cases of
while True:
x = get_item()
if not x: break
process(x)
are better written as:
for x in iterator:
process(x)
--
Steve
More information about the Python-list
mailing list