a gap of do....while?

Stephen Hansen apt.shansen at gmail.com
Sun Oct 18 07:34:06 CEST 2009


On Sat, Oct 17, 2009 at 10:22 PM, StarWing <weasley_wx at sina.com> wrote:

> okay, I think somethings do....while is useful, but why python didn't
> have it?
>
> in lisp, we can (while (progn ....))
> and in all other language we have do...while.
> but in python, we only can:
> cond = 1
> while cond:
>    cond = 0
>    .....
>    if ....: cond = 1
>
> has any polite way to handle this?
>

Although recently there's been a big thread about some people thinking its
bad, the idiomatic way to do it in Python is:

while True:
    ...
    if <test>:
        break

Basically, the answer to "why doesn't Python have a do...while" statement
is-- there's no universally satisfactory way to spell it with Python's
indent-based syntax. Every once in awhile someone proposes a particular way
to do it, but no one has ever really been able to come up with a syntax
everyone likes.

See PEP315 (http://www.python.org/dev/peps/pep-0315/) for the deferred
proposal to add such a construct and links to extensive discussions about
it.

HTH,

--S
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20091017/17e80ec8/attachment.html>


More information about the Python-list mailing list