why no "do : until"?

Andrew Henshaw andrew_dot_henshaw_at_earthling_dot_net
Mon Jan 15 20:48:11 EST 2001


It looks like we're pretty close to agreement.  Like you, I believe that a
conditional with a 'while' is easier to explain to new users.
Conversationally, I can say to my 10-year old, "while the value here
(pointing at the screen) is less than the value here (pointing at the
screen), execute these lines (pointing at the block) over and over."
However, it wouldn't be as easy to explain 'while 1' as it is to explain
'do' for an infinite loop (that can only be *broken* out of).

In fact I think 'do' makes the concept of 'break' easier to explain.  To
first introduce 'break', I'd rather start with the infinitely-looping 'do'.
Then it becomes clear that there is a need for some extreme construct like
'break'.  If you have a 'while 1' at the top, then the question becomes,
"why don't you just change the 'while' so you can get out of the loop?"
Then you have to explain why that's not always possible/desirable.

AH

"Steve Williams" <sandj.williams at gte.net> wrote in message
news:3A633415.47D71944 at gte.net...
> Andrew Henshaw wrote:
...snip...
> But, I'm not a C programmer and 'while 1' doesn't speak to me in a
language I
> can appreciate.
>
> I had the hardest time understanding the ISO on/off switch codes of 1/0.
Was
> this high-level logic or low-level logic?  Using -1 as a truth value is
beyond
> my comprehension--since -1 is less than 1, it must be false. . ..
>
> In any case, I want to see a real conditional as part of the 'while'.
That's
> just the way I'm put together.  And I don't want the conditional used as
some
> kind of tatty scope delimiter fifty lines later.  If you need a scope
delimiter,
> use 'end-while'.
>
> If I have a 'while x <> 0:' statement it tells me something.  It says
"this is a
> loop and this is how it's terminated".  I can then search for the variable
x and
> see who sets it or how it's referenced in the loop.  If I have to prime
the
> value of x before the loop, that's OK with me.  Actually, I like to
initialize
> all my variables.  I'm kind of a control freak that way.
>
> Conversely, when I see 'While 1', all I know is "this is a loop".  I'm now
on
> notice to dig deeper and find out how the loop terminates and hope I get
it
> right.
>
...snip...





More information about the Python-list mailing list