On 7/20/20 7:34 AM, Barry Scott wrote:
To avoid the ambiguity of `if` after `for` why not follow `for` with `elif`?
for x in ...: ...
elif break: # break was called elif not break: # looped at least once and break not used elif pass: # same as else today # loop'ed no times
(I always have to think what else means after a for).
Keep thinking... ;)
`else` today /does not/ mean "loop'ed no times". To copy Steven D'Aprano's example:
py> for x in [1,2]: ... print("inside loop") ... else: ... print("elif never looped") ... inside loop inside loop elif never looped
Mistaking the semantics for "if never looped" is a very common mistake. Welcome to the club :-)