4 ms·
This is the correct place for it to do so. Break skips the check entirely. If the for loop exits normally, the condition was false.
by georgyo 8y ago
This is the correct place for it to do so. Break skips the check entirely. If the for loop exits normally, the condition was false.
- Nition 8y agoYou understand that it can be a confusing code construct though, right? Even in your comments I'm kind of confused at your meaning because you said: > When the condition is false, it breaks. And then you said: > If the for loop exits normally, the condition was false.
- georgyo 8y agoI have updated that comment, a normal loop exit is not the same as a break. I can understand how it can be confusing, but the inverse would not make any sense. Another way to look at a for loop is a fancy while loop that sets a variable by some function. Every loop iteration that function is ran. If the function fails, the loop exits. This is infact how they work. https://anandology.com/python-practice-book/iterators.html#the-iteration-protocol https://anandology.com/python-practice-book/iterators.html#t... If next() fails, that is when the loop exits.
- deleted 8y ago[deleted]