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

Chris Rebert pyideas at rebertia.com
Sun Apr 26 04:49:47 CEST 2009


On Sat, Apr 25, 2009 at 7:35 PM, Larry Hastings <larry at hastings.org> wrote:
<snip>
> It also provides a dandy spelling for early-exit programming, without
> nesting your ifs, or early return, or throwing an exception, or using gotos
> which thankfully we don't have:
>
>   def user_typed_1_then_2():
>       do:
>          print("enter 1, then 2")
>          i = input()
>          break if i != '1'
>          i = input()
>          break if i != '2'
>          return True
>       print("why do you mistreat me so? it was a simple request!")
>       return False

I don't see why the if-as-suffix is needed when we already have a
one-liner for such situations (e.g.):

if i != '1': break

It's much more uniform and only one character longer.

Cheers,
Chris
-- 
I have a blog:
http://blog.rebertia.com



More information about the Python-ideas mailing list