[Python-ideas] for/else syntax

Masklinn masklinn at masklinn.net
Wed Oct 7 16:18:02 CEST 2009

On 2 Oct 2009, at 03:35 , Greg Ewing wrote:
> Yuvgoog Greenle wrote:
>> This
>> construct should have been named "finally", "didnt_break" or "not  
>> break":
> "finally" would be at least as confusing as "else",
> since by analogy with try-finally it suggests that
> it will *always* be executed, which isn't the case.

Then again, a try's finally isn't *always* executed. It's *almost  
always* executed, but if the runtime (or just the thread the block is  
in) crashes, is killed with kill -9 or the machine is shut down, it  
won't be.

Interestingly, because sys.exit throws an exception instead of killing  
the runtime, the finally block does run if you call sys.exit in the  
try block (in Java, it doesn't)

More information about the Python-ideas mailing list