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

Chris Angelico rosuav at gmail.com
Fri Nov 3 23:06:31 EDT 2017


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:
>> On Sat, 4 Nov 2017 06:15 am, Michael Torrie wrote:
>>
>>> In fact if you have no break you may as well drop the
>>> else entirely, because the block will always execute.
>>
>> 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.

ChrisA



More information about the Python-list mailing list