On Sat, Oct 17, 2009 at 10:22 PM, StarWing <weasley...@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
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to