<div dir="ltr">On 23 April 2013 21:49, Terry Jan Reedy <span dir="ltr"><<a href="mailto:tjreedy@udel.edu" target="_blank">tjreedy@udel.edu</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div class="im"><span style="color:rgb(34,34,34)">ri= iter(range(3))</span><br></div>
for i in ri:<br>
    for j in ri:<br>
        print(i,j)<br>
# this is somewhat deceptive as the outer loop executes just once<br>
0 1<br>
0 2<br>
<br>
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<br>
<br>
ri= iter(range(3))<br>
for i in ri:<br>
    break<br>
for j in ri:<br>
    print(i,j)<br>
# this makes it clear that the first loop executes just once<br>
0 1<br>
0 2<br>
<br>
I would only nest if the inner loop could terminate without exhausting the iterator and I wanted the outer loop to then resume.<br></blockquote><div><br></div><div style>Surely a normal programmer would think "next(ri, None)" rather than a loop that just breaks.</div>

</div></div></div>