> they find the "while" logic to be unintuitive<br><br>I've found that a good way to explain 'while' is to consider it as an 'if' statement that repeats. Kids grasp simple conditionals fairly easily. I would sometimes hear them talk about 'if loops' when they were actually trying to discuss conditional statements, and I would say to them hey look, there's no such THING as an 'if loop'! But then it occurred to me - well, that's what a while statement is! So, let's just take a simple conditional, change the 'if' to 'while', and there you have a loop! Only problem, it will keep repeating forever, so now we have to consider ways to get it to stop.
<br><br>Speaking from my own learning experiences, 'while True' initially seemed awkward, probably for the same reason 'if True' would - why bother? But at this point I actually do like the 'while True' structure.
<br><br>- Michel Paul<br><br><div class="gmail_quote">On Dec 12, 2007 3:01 AM, Brian Blais <<a href="mailto:bblais@bryant.edu">bblais@bryant.edu</a>> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div style=""><div><div>On Dec 11, 2007, at Dec 11:11:11 PM, Terry Reedy wrote:</div><br><blockquote type="cite"><div style="margin: 0px; min-height: 14px;"><br></div><div style="margin: 0px;">"Steven D'Aprano" <
<a href="mailto:steve@REMOVE-THIS-cybersource.com.au" target="_blank">steve@REMOVE-THIS-cybersource.com.au</a>> wrote in message<span> </span></div><div style="margin: 0px;"><a href="news:13lts6gb9t2j350@corp.supernews.com" target="_blank">
news:13lts6gb9t2j350@corp.supernews.com</a>...</div><div style="margin: 0px;">||</div><div style="margin: 0px;">| But loops that run at least once is a basic element of algorithms.</div><div style="margin: 0px;">| Perhaps not as common as the zero or more times of the while loop, but
</div><div style="margin: 0px;">| still fundamental. It is a shame it has to be faked using:</div><div style="margin: 0px;">|</div><div style="margin: 0px;">| while True: # force the first iteration to always run</div><div style="margin: 0px;">
|<span> </span>process</div><div style="margin: 0px;">|<span> </span>if condition: break</div><div style="margin: 0px;">|</div><div style="margin: 0px;">| Ugly and misleading.</div><div style="margin: 0px; min-height: 14px;">
<br></div><div style="margin: 0px;">I disagree.<span> </span>Nothing is being faked.<span> </span>The generic loop is</div><div style="margin: 0px; min-height: 14px;"><br></div><div style="margin: 0px;">while True:</div>
<div style="margin: 0px;"><span> </span>pre_process</div><div style="margin: 0px;"><span> </span>if condition: break</div><div style="margin: 0px;"><span> </span>post_process</div><div style="margin: 0px; min-height: 14px;">
<br></div></blockquote><div><br></div><div>I find that when teaching beginning programmers, they usually think in "until" terms, and not "while" terms.</div><div><br></div><div>do:</div><div> Forward()
</div><div>until Touched()</div><div><br></div><div>and I have to explain to them that Python doesn't have "until", and that the logic for while is exactly the opposite:</div><div><br></div><div>while not Touched():
</div><div> Forward()</div><div><br></div><div>they find the "while" logic to be unintuitive, and I often find myself feeling the same way: crafting it with the until logic, and then reversing it. Perhaps I should do as above, and do:
</div><div><br></div><div>while True:</div><div> Forward()</div><div> if Touched(): break</div><div><br></div><div>but somehow that feels wrong to me, like bypassing the point of the while: all that power to check for conditions, and you just use it to check True, and then use a break inside. It's readable, I guess, but not a programming construct I am immediately drawn to.
</div><div><br></div><div><br></div><div><span style="white-space: pre;">                                </span>Brian Blais<br></div><div><br></div><div><br></div></div><div><span style="border-collapse: separate; border-spacing: 0px; color: rgb(0, 0, 0); font-family: Monaco; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;">
<div>-- </div><div>Brian Blais</div><div><a href="mailto:bblais@bryant.edu" target="_blank">bblais@bryant.edu</a></div><div><a href="http://web.bryant.edu/%7Ebblais" target="_blank">http://web.bryant.edu/~bblais</a></div>
<div><br></div><br></span> </div><br></div><br>_______________________________________________<br>Edu-sig mailing list<br><a href="mailto:Edu-sig@python.org">Edu-sig@python.org</a><br><a href="http://mail.python.org/mailman/listinfo/edu-sig" target="_blank">
http://mail.python.org/mailman/listinfo/edu-sig</a><br><br></blockquote></div><br>