[Python-ideas] "while:" for the loop

Chris Angelico rosuav at gmail.com
Tue Sep 25 22:37:13 EDT 2018


On Wed, Sep 26, 2018 at 12:35 PM Michael Selik <mike at selik.org> wrote:
>
> On Tue, Sep 25, 2018 at 8:46 PM Mikhail V <mikhailwas at gmail.com> wrote:
> > I suggest allowing "while:" syntax for the infinite loop.
> > I.e. instead of "while 1:"  and  "while True:" notations.
> >
> > My opinion:
> > 1. I think it'd definitely improve clarity.
>
> I prefer the explicit phrase, ``while True:``. Saying "while" without
> a condition is strange, like a sentence fragment. The ``while 1:``
> pattern is a carryover from Python 2, when ``True`` was not yet a
> keyword.

I like saying while "something": where the string describes the loop's
real condition. For instance, while "moar data": if reading from a
socket, or while "not KeyboardInterrupt": if the loop is meant to be
halted by SIGINT.

ChrisA


More information about the Python-ideas mailing list