while true: !!!

Alex Martelli aleaxit at yahoo.com
Tue Dec 19 08:29:41 EST 2000

"Delaney, Timothy" <tdelaney at avaya.com> wrote in message
news:mailman.977182622.11891.python-list at python.org...
> > >The idiom is actually
> > >
> > >while 1:
> > >
> > > do something
> > >
> > > if condition:
> > > break
> > >
> > > do something else
> I go well out of my way to avoid this idiom, as I feel you should always
> have the termination condition at one end of the loop, preferably the top

I disagree intensely with this stance: I strongly feel that the
loop-exit condition should be *in the most natural place for it*,
which is often the top, but not all that rarely elsewhere.

Anyway, one doesn't have to go 'well' out of one way to hide
this clean, general loop structure as if it was otherwise --
one 'status-variable' will suffice, e.g:

looping = 1
while looping:
    do something
    if condition:
        looping = 0
        do something else

I think this is *substantially* less readable than the
clean, natural form:

while 1:
    do something
    if condition: break
    do something else

but it does satisfy fetishistic adherents of the Jacopini
and Boehm school (and, I believe, _is_ isomorphic to the
local transformation J&B's second lemma would implicitly
perform on the flow diagram of the second form to produce
that of the first).


More information about the Python-list mailing list