[Python-Dev] PEP 3142: Add a "while" clause to generator expressions
Terry Reedy
tjreedy at udel.edu
Thu Jan 22 04:22:55 CET 2009
Cameron Simpson wrote:
>
> Back at uni we had to implement a small language in our compilers class
> and the lecturer had specified a proper generic while loop, thus:
>
> loop:
> suite
> while invariant
> suite
> endloop
In Python, that is spelled
while True:
suite
if not invariant: break
suite
> I think the keywords were better than above, but it neatly handled the
> fact that the while-test must often be preceeded by some setup that
> would be replicated at the loop bottom in Python and many other languages:
>
> setup-invariant-state
> while test-invariant
> do stuff
> setup-invariant-state
Good Python programmers do not repeat the setup code like this.
See the proper say-it-once way above.
This discussion belongs back on Python ideas, where it began and should
have stayed.
tjr
More information about the Python-Dev
mailing list