while (a=b()) ...

Jim Meier fatjim at home.com
Wed May 12 03:29:54 EDT 1999


>
> Again, I'm going to recommend Knuth's "Structured Programming with go
> to statements", which contains 70 pages of discussion of this sort of
> thing, found in his book "Literate Programming".
>
> The method he advocates is basically dynamically generated exception
> names (though he doesn't call them that).
>
> Your loop would look something like this:
>
>   while 1 until done:
>     value = getValue()
>     if not value: done
>     process(value)
>
> 'done' is not a keyword; it's basically an exception (the name of
> which was generated by the 'until' clause) that kicks us out of the
> loop.
>

Just to stick in my own 2cents here, an idiom i find extremely readable
is this:

done=false
while not done:
    (do stuff)
    if test:
        done=true

Which seems very similar but without magic language changes.

What do previously unnamed variables default to having value None?
I should check this..





More information about the Python-list mailing list