PEP 284, Integer for-loops

David Eppstein eppstein at ics.uci.edu
Thu Mar 7 12:36:10 EST 2002


In article <slrna8dd1d.d3t.philh at comuno.freeserve.co.uk>,
 philh at comuno.freeserve.co.uk (phil hunt) wrote:

> How about:
> 
>    for i = 1 to 10:
> 
> or
> 
>    for i is 1 to 10:
> 
> I think these are both equally good and both much preferable over 
> the horrible
> 
>    for 1 <= i <= 10:
> 
> which I can only assume is someone's sick idea of a joke.

Your "1 to 10" syntax (and most other ideas floated previously on this 
group) assumes a fixed type of interval (closed, I'm guessing, but it's 
not clear), and not even the most common type (half-open).  The proposed 
syntax makes explicit what would happen at the ends of the intervals.

One alternative proposal, that didn't seem to have as much support but 
might still be worth looking at, was to allow the creation of ranges by
"1 <= ... <= 10" (possible without much modification of the compiler via 
a clever enough definition of "...") so then one could do
"for i in 1 <= ... <= 10".

I would appreciate it if you could give me a more constructive criticism 
of PEP 284 than "horrible", "someone's sick idea of a joke", which don't 
give me much idea why you don't like it.



More information about the Python-list mailing list