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

bartc bc at freeuk.com
Wed Nov 1 21:33:58 EDT 2017


On 02/11/2017 01:19, Steve D'Aprano wrote:
> On Thu, 2 Nov 2017 08:21 am, Chris Angelico wrote:
> 
>> With the 'for' loop,
>> it's a bit more arguable, but I've never seen anything more than a
>> weak argument in favour of 'then'
> 
> Thhpptpt!
> 
> "else" is an completely inappropriate term that doesn't describe the semantics
> of the statement even a little bit. The argument that it means "else no
> break" is feeble because break is not the only way to exit the loop and
> therefore skip executing the else clause.
> 
> It is not even necessarily the most common: I wouldn't be surprised if there
> were more returns out of the middle of a loop than breaks, although I
> wouldn't necessarily predict it either.
> 
> If we spoke in ordinary English using "else" the way Python uses it for
> looping, we would say:
> 
> "Shampoo your hair twice, ELSE apply conditioner and leave for five minutes
> before rinsing."
> 
> "Boil the pasta until it is soft, ELSE drain it and mix in the sauce."

1 Start boiling the pasta
2 Wait one minute
3 If it's not soft (some of us prefer al dente), repeat from step 2,
   else drain it



More information about the Python-list mailing list