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

Greg Ewing greg.ewing at canterbury.ac.nz
Sun Apr 26 13:23:55 CEST 2009


Ron Adam wrote:

> I'd prefer a bare "while:" with a more visible "break if" and possibly 
> "continue if" expressions.
> 
>      while:
>          j = _int(random() 8 n)
>          break if j not in selected

But putting "if" after "break" doesn't make the exit
point any more visible to my eyes. If anything, it
makes it *less* visible.

I think there's another thing at work here, too. Having
an outdented clause for the exit point makes it very
obvious that it is part of the syntax of the loop
structure, and consequently that there is only *one*
exit point from the loop. This is in contrast to
break statements, which are much less disciplined and
can occur more than once and inside nested statements.

-- 
Greg



More information about the Python-ideas mailing list