Concrete Proposal: while ... and while ...

Corran Webster cwebster at math.tamu.edu
Wed May 19 09:47:23 EDT 1999


In article <y0j675pmg6c.fsf at vier.idi.ntnu.no>,
Magnus L. Hetland <mlh at idt.ntnu.no> wrote:
>cwebster at math.tamu.edu (Corran Webster) writes:
>
>I thought the Guido-approved version had a condition on the first as
>well (i.e. an expansion of the standard while loop)?
>
>Thus:
>
>while 1:
>  ...
>and while something:
>  ...

It might be the Guido-approved version - I can't recall the exact form
of the approved form.  If this is in fact it, then I think my proposal
has a slight advantage over this in simplicity.  This form allows two
tests (presuming something other than '1' is permitted after the first
while), where my proposal has precisely one test for the loop, which
seems more natural to me.

>Of course, that doesn't remove the ugliness of the "while 1" but it
>does alleviate the use of "break". I guess your suggestion actually
>adds the syntax of "while:" for "while 1:" as well -- or is it only in
>the use with "and while" that it is permitted?

No, "while:" is not permitted without the "and while" later.  The precise
grammar is

while [':' suite 'and' 'while'] test ':' suite ['else' ':' suite]

and it's implemented by simply inserting the optional suite before
the test - this means the changes to the source are fairly simple.

It seems to me that with this change, 'while 1:' will be used much
less often, and it's not worth the additional complexity to make
the '1' optional.

Corran





More information about the Python-list mailing list