replacing `else` with `then` in `for` and `try`

Jon Ribbens jon+usenet at unequivocal.eu
Sat Nov 4 08:22:28 EDT 2017


On 2017-11-04, Michael Torrie <torriem at gmail.com> wrote:
> On 11/03/2017 09:06 PM, Chris Angelico wrote:
>> On Sat, Nov 4, 2017 at 1:57 PM, Michael Torrie <torriem at gmail.com> wrote:
>>> On 11/03/2017 07:09 PM, Steve D'Aprano wrote:
>>>> That's incorrect. There are multiple ways to exit a loop that
>>>> will prevent the `else` block from executing, `break` is only one.
>>>
>>> Such as?
>> 
>> There are many. But other than break, I don't know of any that WOULD
>> execute the next line of code immediately _after_ the loop.
>
> Can you be more specific? What are some of these "many" ways of aborting
> a loop?  Help a guy out here.
>
> I know, for example, that we have exceptions. But those hardly matter in
> this discussion because they wouldn't execute the else clause either.
> They'd either be caught elsewhere, or end the program.  sys.exit() can
> also terminate a for loop, but it terminates the whole program without
> running the else statement.

Yes, those are the sort of thing that Steve was referring to.
He was being unhelpfully pedantic. A giant meteor destroying
the computer the program was running on would prevent the 'else'
block from executing too.



More information about the Python-list mailing list