logoalt Hacker News

arccytoday at 1:39 AM2 repliesview on HN

isn't break more normal


Replies

zephentoday at 3:11 AM

The point is that the use of exceptions is built into the language, so, for example, if you write "for something in somegeneratorfunction():" then somegeneratorfunction will signal to the for loop that it is finished by raising this exception.

pansa2today at 2:53 AM

I’d say it’s more common for iterator-based loops to run to completion than to hit a `break` statement. The `StopIteration` exception is how the iterator signals that completion.