<br class="Apple-interchange-newline"><div><br></div><div> On Sat, Jun 9, 2012 at 10:48 AM, Steven D'Aprano <span dir="ltr"><<a href="mailto:steve@pearwood.info" target="_blank">steve@pearwood.info</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="im">Loops exit at the top, not the bottom. This is most obvious when you think about a while loop:</div>
<br>while condition:<br> ...<br><br><br>Of course you have to be at the top of the loop for the while to check condition, not the bottom. For-loops are not quite so obvious, but execution has to return back to the top of the loop in order to check whether or not the sequence is exhausted.<br>
<br>Whether or not it is the *simplest* way to think about for/else, talking about exhaustion of the list (iterable) is correct.<br class="Apple-interchange-newline"></blockquote><div><br></div><div>If you want to talk about exhaustion of the list then you need to talk differently about the while loop. Documentation is usually written for non-experts. When I taught intro to programming, the mental model that most students had was nowhere near as strong as most people on this list. The concept 'loop exits normally' would be much easier for them to understand.</div>
<div><br></div><div><br></div><div>On Sat, Jun 9, 2012 at 10:49 AM, Steven D'Aprano <span dir="ltr"><<a href="mailto:steve@pearwood.info" target="_blank">steve@pearwood.info</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div class="im">Ignoring try/finally blocks, which are special, we can assume that the reader has (or will have once they actually learn about functions and exceptions) a correct understanding of the behaviour of return and raise.</div>
<br>- If the loop is exited by a return, *nothing* following the return is executed. That includes the else block.<br><br>- If execution is halted by an exception (including raise), *nothing* following the exception is executed. That includes the else block.<br>
<br>- If execution is halted by an external event that halts or interrupts the Python process, *nothing* following executes. That includes the else block.<br><br>- If the loop never completes, *nothing* following the loop executes. That includes the else block.<br>
</blockquote><div><br></div>You've written four different ways of saying 'loop does not exit normally' vs. saying once 'loop exits normally'. When you emphasize *nothing* above, it strongly suggests they all mean the same thing. If you *don't* ignore try/finally, then they don't. I don't think documentation needs to cover every case, but if you're going to write stuff in bold letters (or italic or whatever), then readers expect you're covering all the bases and not ignoring special cases. That may not be your intent but that's the way people read things. Again, docs are written for non-experts.</div>
<div><br></div><div><span style="font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"> Holly: He's dead, Dave. Everybody is dead. Everybody is dead, Dave.</span><br style="font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
<span style="font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"> Lister: Wait. Are you trying to tell me everybody's dead?</span>
</div><div><span style="font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"> Holly: Yup. Well, except for Dracula who was executing a try/finally. He's undead and probably going to kill you too. But I didn't want to bother you with that minor detail.</span></div>
<div><span style="font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><br></span></div><div><span style="font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">:-)</span></div>
<div><div><br></div></div><div><font face="arial, helvetica, sans-serif">--- Bruce</font><div><font face="arial, helvetica, sans-serif">Follow me: <a href="http://www.twitter.com/Vroo" target="_blank">http://www.twitter.com/Vroo</a> <a href="http://www.vroospeak.com" target="_blank">http://www.vroospeak.com</a></font></div>
<div><font face="arial, helvetica, sans-serif"><br></font></div><br>
<br> </div></div>