[Python-ideas] if-statement in for-loop

Sven R. Kunze srkunze at mail.de
Tue Oct 4 11:06:29 EDT 2016


On 04.10.2016 15:20, Random832 wrote:
> The *real* question is what "break" should do. I think it should
> likewise break from the outermost for-loop (but "continue" should still
> continue the innermost one), but this does mean that it's not
> mechanically identical to the "equivalent" nested loops [it would,
> however, make it mechanically identical to the "generator and single
> loop" form]

To me, a for loop starts with a "for" and ends with a ":". I wouldn't 
mind the ability of more "for"s or "if"s in between. I would skip over 
them anyway while reading. Technically, I agree with you as it matches 
my intuition:

for blaa foo blah blaaaa blubber babble:
     break    # go outside
     continue # go to next item
else:
     # no break

Cheers,
Sven



More information about the Python-ideas mailing list