PEP 315: Enhanced While Loop

Charles Hixson charleshixsn at earthlink.net
Tue May 6 13:23:20 EDT 2003


W Isaac Carroll wrote:
> PEP: 315
> Title: Enhanced While Loop
> Version: $Revision: 1.1 $
> Last-Modified: $Date: 2003/05/02 22:53:32 $
> Author: W Isaac Carroll <icarroll at pobox.com>
> Status: Draft
> Type: Standards Track
> Content-Type: text/plain
> Created: 25-Apr-2003
> Python-Version: 2.4
> Post-History:
> 
> 
> Abstract
> 
>     This PEP proposes adding an optional "do" clause to the beginning
>     of the while loop to make loop code clearer and reduce errors
>     caused by code duplication.
...
Perhaps this should be done in a more general way.  Just create a block 
keyword, do: is fine.

what this keyword does is introduce a logical level of grouping (i.e., 
the code underneath it is indented once.)  It is strictly equivalent to
"if True:"

Whether this would be worthwhile or not, I don't know, but it seems both 
simple and sufficient to satisfy what I understand of your request.
I.e., it would allow one to write
do:
    """ some code """
while(test):
    """ some more code """

Unfortunately, I can think of many variations on this that would be 
equally valuable, e.g., one that only executes once, or only executes 
when a control variable == None, or one that locks access when another 
thread is using it or...
And with so many similar plausibilities, probably none of them are 
really appropriate (though that sync method has arguments, Java has 
something like that).
-- 
-- Charles Hixson
Gnu software that is free,
The best is yet to be.





More information about the Python-list mailing list