[Python-ideas] "while:" for the loop
mikhailwas at gmail.com
Tue Sep 25 20:46:31 EDT 2018
I suggest allowing "while:" syntax for the infinite loop.
I.e. instead of "while 1:" and "while True:" notations.
IIRC, in the past this was mentioned in python-list discussions as
alternative for the
"while True:"/"while 1:" syntax. I even had impression that there was nothing
rational against this (apart from the traditional "don't change
1. I think it'd definitely improve clarity. Although it's not
extremely frequent statement,
it still appears in algorithms, where additional noise interfers the
2. This should become the answer to the "how should I denote an
infinte loop?" question.
3. In schools/unis they teach algorithms with Python syntax so it will
be easier to
remember and to write. Adoption of this spelling is natural and straightforward.
4. It does seem to be a rare case of a very easy to implement syntax
change (an expert note needed)
Also I have personal sympathy for this because I like to use explicit
"break" in the loop
body, even though I could use "while expression:" syntax, but I prefer this:
if i == N : break
instead of this:
while i < N:
It helps me to concentrate by reading, especially in nested loops and
those situations with
multiple break points. So by me this syntax would definitely achieve an extra +.
There were alternative suggestions, e.g. introducing a new keyword
"loop", but obviously
a new keyword is much harder to do now.
I don't know what to add to this actually, I think the idea is
understood. I see, it is not the
most important problem, but if there is nothing serious against this,
I think it's worth it and
would be quite a positive (small) improvement and a nice gift to those
involved in algorithms.
As for statistics - IIRC someone gave statistics once, but the only
thing I can remember -
"while 1/True" is used quite a lot in the std lib, so the numbers
exceeded my expectation
(because I expected that it's used mostly in algorithms).
More information about the Python-ideas