[Edu-sig] "do" as a keyword

michel paul mpaul213 at gmail.com
Wed Dec 12 17:11:32 CET 2007


> they find the "while" logic to be unintuitive

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.

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.

- Michel Paul

On Dec 12, 2007 3:01 AM, Brian Blais <bblais at bryant.edu> wrote:

> On Dec 11, 2007, at Dec 11:11:11 PM, Terry Reedy wrote:
>
>
> "Steven D'Aprano" <steve at REMOVE-THIS-cybersource.com.au> wrote in message
> news:13lts6gb9t2j350 at corp.supernews.com...
> ||
> | But loops that run at least once is a basic element of algorithms.
> | Perhaps not as common as the zero or more times of the while loop, but
> | still fundamental. It is a shame it has to be faked using:
> |
> | while True: # force the first iteration to always run
> |    process
> |    if condition: break
> |
> | Ugly and misleading.
>
> I disagree.  Nothing is being faked.  The generic loop is
>
> while True:
>     pre_process
>     if condition: break
>     post_process
>
>
> I find that when teaching beginning programmers, they usually think in
> "until" terms, and not "while" terms.
>
> do:
>     Forward()
> until Touched()
>
> and I have to explain to them that Python doesn't have "until", and that
> the logic for while is exactly the opposite:
>
> while not Touched():
>     Forward()
>
> 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:
>
> while True:
>     Forward()
>     if Touched(): break
>
> 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.
>
>
> Brian Blais
>
>
> --
> Brian Blais
> bblais at bryant.edu
> http://web.bryant.edu/~bblais <http://web.bryant.edu/%7Ebblais>
>
>
>
>
> _______________________________________________
> Edu-sig mailing list
> Edu-sig at python.org
> http://mail.python.org/mailman/listinfo/edu-sig
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/edu-sig/attachments/20071212/c4cbd6f3/attachment.htm 


More information about the Edu-sig mailing list