Re:The optional “else” in Python loops
by BWStearns on Thursday July 17, 2014 @08:41PM
(#8051103)
That logic definitely helps me think about it. But it does seem like a switch from the other wording that python uses. Feels like finally would be more intuitive, whereas without thinking about the search loop case else feels like something that would be triggered by a break or return. I wonder if using the feature would be more common if it was more intuitively worded.
[ Parent
| on HN ]
Re:The optional “else” in Python loops
by maxerickson on Thursday July 17, 2014 @10:23PM
(#8051351)
It's analogous to the natural termination of a while-else, where the else block is executed after the condition evaluates to false:
>>> a=1
>>> while a>0:
print(4)
a=a-1
else:
print('done')
4
done
clarity cribbed from here: https://mail.python.org/pipermail/python-list/1999-July/0044...Oh, that helps too -- it's an else clause for the conditional of the while loop :D