loop scope

Donn Cave donn at drizzle.com
Fri Mar 12 01:34:30 EST 2004


Quoth user at domain.invalid:
| Terry Reedy wrote:
|
|> For loops with a break statement, the value of the loop index when the
|> break occurs may be the answer sought or needed to calculate it.  For list
|> comps which cannot have break, it is an artifact which may disappear in
|> 2.4.
|
| If I understand you, I don't think I like this idea. It 
| adds complexity to the mental model of a loop. "The 
| loop variable disappears when the loop ends unless the 
| loop contains a break".
|
| In my opinion, Python should pick a model and stick to 
| it. Loop variables are either ordinary variables that 
| exist until you explicitly delete them, or they are 
| special variables that automagically disappear at the 
| end of the loop. I vote for the first one.

That makes sense to me, but I read "For list comps" as "For list
comprehensions (but not conventional loops.)"  List comprehensions
shouldn't need to have every side effect of the equivalent loop.

	Donn Cave, donn at drizzle.com



More information about the Python-list mailing list