PEP 276 Simple Iterator for ints (fwd)

Greg Ewing greg at cosc.canterbury.ac.nz
Thu Dec 6 18:53:43 EST 2001


David Eppstein wrote:
> 
> if "for x in list" doesn't change subsequent iterations if you
> rebind x or list within the loop body, neither should "for x <= i < y"
> or whatever similar syntax one uses. So that means, it should construct an
> iterator and then act as if it were called by "for i in iterator"

I think relying on the semantics of changing the
loop variable in a loop is a bad idea in the first
place, so the difference wouldn't worry me.

In any case, you can get the same semantics quite
easily without the need for an iterator: keep the
real loop counter in a hidden variable, and assign
it to the user's loop variable before each iteration.

-- 
Greg Ewing, Computer Science Dept, University of Canterbury,	  
Christchurch, New Zealand
To get my email address, please visit my web page:	  
http://www.cosc.canterbury.ac.nz/~greg



More information about the Python-list mailing list