[Python-ideas] Updating PEP 315: do-while loops

spir denis.spir at free.fr
Sun Apr 26 14:17:20 CEST 2009

Le Sat, 25 Apr 2009 21:50:52 -0500,
Ron Adam <rrr at ronadam.com> s'exprima ainsi:

> Visualize the while, continue, and break with syntax highlighting.
>       while:
>           j = _int(random() 8 n)
>           break if j not in selected
> Or if the reverse comparison is preferred you could do...
>       while:
>           j = _int(random() * n)
>           continue if j in selected
>           break


(1) This does not give any advantage compared to existing syntax
   if condition: break | continue

(2) It does not solve the problem which, I guess, is to express the loop's logic obviously -- meaning in the header (or footer) instead of hidden somewhere in the body -- and nicely avoid numerous "while 1:" and "break" as a side-effect. What Raymond's proposals provide.

What is not obvious at all is that:
    do ... while j in selected:
        j = _int(random() * n)
means the assignment will be done at least once (and no NameError thrown). Where/how is it said? The above code is supposed to mean something like:

    do once then while j in selected:
        j = _int(random() * n)

But maybe it's only me.
Footer solutions (condition at end of loop) seem not to have Raymond's favor; still they are obvious in comparison:

        j = _int(random() * n)
  <your favored end condition syntax> j in selected

la vita e estrany

More information about the Python-ideas mailing list