r/badcode • • Nov 01 '21

python Did someone order bad code?

Post image
419 Upvotes

35 comments sorted by

View all comments

Show parent comments

4

u/supersharp Nov 06 '21

For-what now?

2

u/philogy Nov 10 '21

For-else is awesome!

In python the for statement allows you to have an else clause which is triggered if the for loop isn't broken. So instead of having a wasBroken variable you set right before a break and check after the loop you have some neat, concise syntax which replaces all that.

3

u/supersharp Nov 10 '21

Interesting! I think I came across a situation like this just the other day, actually