do ... while loop

Tim Peters tim_one at email.msn.com
Sat Oct 16 06:19:29 EDT 1999


[Joshua Marcus]
> ...
> There are, in fact, other situations in which one actually wants a
> "do...while" loop & one is forced to either repeat code or make a
> meaningless initial assignment.

[Tim]
> Those are never necessary, although it's amazing how often
> people fall into believing they are.  The usual Python idiom ...

[Cameron Laird]
> It amazes me less than you.

Are you picking a fight again <wink>?

> Surely you remember the pedagogic fashion--is it still in bloom?--of
> preferring "single-exit" control structures.

It's alive and well, at least in Eiffel.  No "early exit" loops there!  If
there's only one exit, the conjunction of the sole exit condition and the
loop invariant must establish the loop postcondition, and that makes the
proof framework as simple as possible.  That's a Great Good, so far as it
goes.  Which is, alas, approximately nowhere:  the day serious reasoning
about programs becomes widespread is the day most programmers abandon their
craft to resume drug trafficking <wink>.

> I suspect many of the people stumbling around in this area bear that
> burden still; they fear someone will "take off points" for every break
> or continue.

Well, they will lose points, and they should.  But they also gain points for
not ending up with a single exit condition choked with six artificial
Boolean vrbls -- trading control complexity for data complexity may fool the
automated complexity-checker, but the code is still a mess.  Let's see ...
there are 856 gotos in Python's source code -- Guido must agree <wink>.
(Odd!  Before counting, I would have sworn there were only a handful ...
hmm, over 216 in almodule.c alone ... it's a *very* lumpy distribution.)

> Also, Mr. Niksic is right to posit that a "while 1 ..." looks
> suspicious to newcomers.

I agree -- heck, it still looks suspicious to me!  "while 1" is not a good
thing; but all in all it is a minor thing.

>> Has been debated many times.  There's no pleasant way to spell
>> it in Python; all blocks have opening keywords, but never closing
>> keywords.

> I'm thinking about whether that'll help a LOT in getting the message
> through.

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>.

leave-'em-alone-and-they-inflate-themselves-to-absurdity-ly y'rs  - tim






More information about the Python-list mailing list