PEP 284, Integer for-loops

Sean 'Shaleh' Perry shalehperry at attbi.com
Wed Mar 6 12:30:19 EST 2002


On 06-Mar-2002 David Eppstein wrote:
> On 3/6/02 9:08 AM -0800, Sean 'Shaleh' Perry wrote:
>> From watching the lists I have seen more people looking for C
>> style for(;;) loops than anything.  The syntax you propose is extremely
>> confusing to anyone who has used a for loop in C.  My other complaint is
>> the lack of generality caused by not using the C syntax.
> 
> Thanks for the comments, but it seems clear (and I think it's a good thing) 
> that C-style for's are not going to happen in Python.  They're very 
> general, but not very intuitive, especially to non-C-programmers.
> 

The intention was not 'we should have C style for loops'.  Rather, I was trying
to point out the limited gain from adding the propsed syntax.  I personally
find it annoying to have special case syntax.

Loop over the first M numbers in a sequence:

for n <= var < n+m: print var

Loop over the even numbers between N and M:

for var in xrange(n, m, 2): print var

A new programmer frequently tries something simple like the first item, then
moves onto the second.  I believe they would be equally confused by the need
for a completely different syntax.




More information about the Python-list mailing list