On 23 April 2013 21:49, Terry Jan Reedy <tjre...@udel.edu> wrote: > ri= iter(range(3)) > for i in ri: > for j in ri: > print(i,j) > # this is somewhat deceptive as the outer loop executes just once > 0 1 > 0 2 > > I personally would add a 'break' after 'outer_line = next(f)', since the > first loop is effectively done anyway at that point, and dedent the second > for statement. I find to following clearer > > ri= iter(range(3)) > for i in ri: > break > for j in ri: > print(i,j) > # this makes it clear that the first loop executes just once > 0 1 > 0 2 > > I would only nest if the inner loop could terminate without exhausting the > iterator and I wanted the outer loop to then resume. >
Surely a normal programmer would think "next(ri, None)" rather than a loop that just breaks.
-- http://mail.python.org/mailman/listinfo/python-list