So why use the word "else" when it really does not mean what users consider else?
Again, we have words like "finally" used in some places to mean it should be done no matter what, like closing a file that may be open. What phrase used either in one or all contexts might have been better, if longer? I mean in the case where your while is NOT entered, "else" almost makes sense. But it could also have been loop_skipped or something. In other cases, it could be some name like "loop_completed_normally" or whatever. Reusing the keyword "else" over and over for "if" statements and perhaps some kind of case/switch statement and while loops and so on, may be parsimonious but ... -----Original Message----- From: Python-list <python-list-bounces+avigross=verizon....@python.org> On Behalf Of Alan Gauld via Python-list Sent: Friday, September 10, 2021 11:58 AM To: python-list@python.org Subject: Re: Friday Finking: Contorted loops On 10/09/2021 16:36, MRAB wrote: >> while...else... >> >> executes the else if the body of the loop does NOT get executed. >> >> for...else... >> >> executes the else iff ALL iterations of the for loop DO complete. >> > [snip] > > In both cases, it executes the 'else' part if it didn't break out of > the loop. That's it. OK, That's a useful perspective that is at least consistent. Unfortunately it's not how beginners perceive it and it causes regular confusion about how/when they should use else with a loop. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list