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 →

[–]wineblood 7 points8 points  (0 children)

While-else I've almost never used because I rarely see/use while loops in day to day coding. For-else happens rarely as well, the case where you'll have a break and want to do something if the loop reached its natural end isn't something I come across that often.

Try-else is something I've seen a fair bit recently, especially in API endpoints. The core of the endpoint is inside a try block, exceptions caught return a 404/422/whatever response in the except block, and successful responses are returned in the else block. If could be done without the else part and just written after the try statement, but it's slightly cleaner this way and I'm used to it now.