On Dec 11, 2007, at Dec 11:11:11 PM, Terry Reedy wrote:
"Steven D'Aprano" <[EMAIL PROTECTED]> wrote in
message
news:[EMAIL PROTECTED]
||
| 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
[EMAIL PROTECTED]
http://web.bryant.edu/~bblais
--
http://mail.python.org/mailman/listinfo/python-list