[Python-ideas] for/except/else syntax

Adam Atlas adam at atlas.st
Wed Oct 7 20:26:39 CEST 2009


On 7 Oct 2009, at 11:17, Andrey Fedorov wrote:
> Agree with Rob that the "else" keyword confusing in the context of a  
> for loop. In my mind, "for each pebble in the bag, give it to Ben,  
> or else ..." has no clear semantic meaning. What do you mean, "or  
> else"?

That wouldn't have any particular meaning in Python either (in that  
the "else" clause would never execute). If you had an example where  
there *was* some use for the "else" clause, it might make more sense  
in an English interpretation too. Maybe something like, "for each  
pebble in the bag, when you get to a blue one, give it to Ben and  
stop, or else...". Not the best way to phrase it, but it's  
comprehensible.

> In my mind, better words for what "else" currently does seem to be  
> "afterwards", "atend", "ending", "thereafter", or "subsequently".

I don't think any of those really sound like what the "else" clause  
does... they all just sound like something to execute when the loop is  
done, which is what happens after the loop body anyway. Switching to  
any of those words would probably only make it more unintuitive.

- Adam



More information about the Python-ideas mailing list