<div dir="ltr">The way I remember it is to observe that the following are *almost* exactly the same thing:<div><br></div><div>if C:</div><div>    T</div><div>else:</div><div>    E</div><div><br></div><div>while C:</div><div>    T</div><div>else:</div><div>    E</div><div><br></div><div>The *only* differences are:</div><div><br></div><div>1) where execution jumps if it reaches the end of the T: in the "while", it jumps back to the while itself, resulting in the condition being rechecked, whereas in the "if" execution skips over the "else" to whatever follows; and</div><div><br></div><div>2) in the "while", inside the T "break" and "continue" relate to this control structure rather than to a containing loop.</div><div><br></div><div>(At least I don't think I'm missing any other differences!)</div><div><br></div><div>Seen this way, the meaning of the "else" is easy to understand and to remember.</div><div><br></div><div>And the for loop else is like the while loop else.</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 24 July 2017 at 11:35, Kiuhnm via Python-Dev <span dir="ltr"><<a href="mailto:python-dev@python.org" target="_blank">python-dev@python.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello,<br>
<br>
I think that the expression "for...else" or "while...else" is completely counter-intuitive. Wouldn't it be possible to make it clearer? Maybe something like<br>
<br>
    break in for i in range(n):<br>
      ...<br>
      if cond:<br>
        break<br>
    else:<br>
      ...<br>
<br>
I'm not an English native speaker so I don't know whether "break in" is acceptable English in this context or can only mean "to get into a building by force".<br>
<br>
Kiuhnm<br>
______________________________<wbr>_________________<br>
Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org" target="_blank">Python-Dev@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-dev" rel="noreferrer" target="_blank">https://mail.python.org/mailma<wbr>n/listinfo/python-dev</a><br>
Unsubscribe: <a href="https://mail.python.org/mailman/options/python-dev/isaac.morland%40gmail.com" rel="noreferrer" target="_blank">https://mail.python.org/mailma<wbr>n/options/python-dev/isaac.<wbr>morland%40gmail.com</a><br>
</blockquote></div><br></div>