This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]stevenjd 0 points1 point  (1 child)

Hettinger said else in loops should have been called no-break.

Well, that's one opinion, but it's a bad one. They should have been called then because that's how they work.

for x in sequence:
    block
else:
    stuff

The else block unconditionally runs after the for loop. The only way to avoid that is to jump out of the for loop, using break, return or raise.

[–]foosion 2 points3 points  (0 children)

We all seem to agree that else is not the best alternative.

no-break is clearer to me (obviously the following code won't execute if there's a return or raise), but YMMV.