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

Eric Smith eric at trueblade.com
Sun Apr 26 03:31:17 CEST 2009

Raymond Hettinger wrote:
> Am working on PEP 315 again, simplifying the proposal by focusing on a 
> more standard do-while loop.

I posted this to python-dev before I saw your post over here. Sorry 
about that.

My message was:
You might want to note in the PEP that the problem that's being solved 
is known as the "loop and a half" problem, at least for your motivating 
case #2.


> 2) A pattern of ending a "while True:" loop with an "if not <cond>: 
> break".  Here's an example from random.normalvariate():
>    while 1:
>        u1 = random()
>        u2 = 1.0 - random()
>        z = NV_MAGICCONST*(u1-0.5)/u2
>        zz = z*z/4.0
>        if zz <= -_log(u2):
>            break

More information about the Python-ideas mailing list