Hello,
On Wed, 22 Jul 2020 09:45:31 +1000
Steven D'Aprano
On Tue, Jul 21, 2020 at 10:07:47PM +0100, Barry wrote:
1. Because that not what else mean today. Its elif never looped.
py> for x in [1,2]: ... print("inside loop") ... else: ... print("elif never looped") ... inside loop inside loop elif never looped
This is why I have long-argued that the keyword here should be *then* not else. The semantics are that the loop executes, *then* the following "else" block executes,
But no, loop executes, *or else* the following "else" block executes ;-). That's the logic of founding fathers. After one grasped that logic, one comes to appreciate a weird beauty of it. The verdict remains the same though: "Do Not Use".
unless we have transferred control elsewhere by jumping out of the loop with return, raise, or break.
Mistaking the semantics for "if never looped" is a very common mistake. Welcome to the club :-)
-- Steven
[] -- Best regards, Paul mailto:pmiscml@gmail.com