do ... while loop

John W. Stevens jstevens at basho.fc.hp.com
Thu Oct 21 14:49:28 EDT 1999


Tim Peters wrote:
> Which message would that be?  I have no objection to richer loop constructs,
> so that's not *my* message <wink>.  As the resident Hoary Corporate
> Apologist, my only message is that It's All In The Archives, and the chance
> of anything changing here in Python1 is zero.  The only thing that ever got
> close to having a fighting chance (largely thanks to introducing no new
> keywords) was the "and while" statement; and that committed hypergeneralized
> suicide when it got expanded to the truly eccentric "and if" stmt.  This is
> why Guido so rarely has to squash a suggestion <0.5 wink>.

It does seem, however, as if the whole thing could be resolved by doing:

1) Introduce the loop keyword.
2) Put an (optional) condition on break (and continue as well, if you
wished).

So you could write:

loop:
    break not <condition>
    <statments>

Would be similar to a while.

loop:
    <statements>
    break <condition>

Would be your do while, and:

loop:
    <statements>
    break <condition>
    <statements>

Would be something we've all done, but up to now, never had a really
good
way of expressing in most languages.

If the concept of two kinds of break: optional and mandatory is a
sticking
point, I suppose something like breakon, or breakif could be added, but
for the life of me, I can't see why an optional condition on break would
be a problem.

'Course, you'd have to get used to writing your conditions so that they
were true for exiting on break, but that wouldn't be to hard, would it?

I-am-going-to-scream-if-I-see-one-more-hyphen'ly yours,

John S.
============

If I spoke for HP --- there probably wouldn't BE an HP!

John Stevens
john_stevens at fc.hp.com




More information about the Python-list mailing list