[Python-ideas] SyntaxWarning for for/while/else without break or return?
steve at pearwood.info
Fri Oct 9 05:00:25 CEST 2009
On Fri, 9 Oct 2009 06:09:19 am Jared Grubb wrote:
> (Just for completeness, I suppose 'yield' is a third way; but like
> return/raise, it makes the else unnecessary)
That's incorrect. Code after a yield will (in general) be executed, when
you call the iterator again. E.g.:
for x in [1, 2, 3]:
if y == 0: break
gen(1) will yield 1, 2, 3, 0, -1.
More information about the Python-ideas