Friday Finking: Contorted loops

alister alister.ware at ntlworld.com
Sun Sep 12 10:05:05 EDT 2021


On Sun, 12 Sep 2021 10:11:15 +0200, jak wrote:

> -- snip --
>> 
>> An inconsistency that I have been able to notice is this:
>> someone suggests to remedy the absence of the do-while with:
>> while True:
>>       ...
>>       if condition:
>>           break
>> the problem arises if the while has an else of its own because the
>> break not only blocks the while loop but will also ignore the relative
>> else.
>> 
>> 
> I will try to make my doubt clearer:
> if the only way to terminate a 'while True' loop is by using the 'break'
> statement, why is it allowed to add the 'else' statement which will only
> contain dead code?
> 
> while True:
>      break
> else:
>      print('dead code')

Because adjusting the parser for one specific special case is not worth 
the effort.
it is not the job of the interpreter to sanitise stupid programming

"Special Cases aren't special enough the break the rules"




-- 
If you stew apples like cranberries, they taste more like prunes than
rhubarb does.
		-- Groucho Marx


More information about the Python-list mailing list