Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> So when you explicitly break, the for body was executed.

Maybe that is what is technically happening, I honestly don't know what that means.

I consider the body of a for statement to be execute for every loop, and for the loop to normally end when all values have been iterated. And else-clause is something that happens instead of the intended clause, which makes it very hard to fit in.

Reading through the comments here, there does seem to exist a mental model where the else makes sense. Something along the lines of

`if` there still is a value to assign to `i` do `loop-body`, `else` do `else-body`.

You can learn that, and it does make sense, but it is not the mental model the majority of people will build when they see a normal for loop in Python.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: