PEP-315 ("do" loop)

Josiah Carlson jcarlson at nospam.uci.edu
Thu Feb 19 22:41:29 CET 2004


> Amen to that! I think this is only a matter of education. People
> should be told that 'while 1' construct is a good, simple, pythonic
> way to do the thing. They are often prejudiced, thinking that there is
> something 'wrong' with the construct. Hearing that it's ok to do
> things this way can actually be very liberating: there is no reason to
> feel guilty, and they will quite soon learn to appreciate how natural
> and versatile the construct is.
> 
> Naming it 'loop' would drive the point even further, of course.

The nice thing about while is that it is general.  You can put anything 
that returns some value that can be tested for truthfulness, even 1 (as 
we like to do).  Changing the name alters the linguistic interpretation 
of what goes on.  Using "loop" would suggest a subsequent "until":

loop:
     #setup
     #loop internals
until <failure condition> | <not successful condition>

Which is clearer, but adds two keywords.  Though, like I said before, 
the while setup is perfectly understandable.

  - Josiah



More information about the Python-list mailing list