a gap of do....while?

Discussion in 'Python' started by StarWing, Oct 18, 2009.

  1. StarWing

    StarWing Guest

    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?
    StarWing, Oct 18, 2009
    #1
    1. Advertising

  2. StarWing

    Chris Rebert Guest

    On Sat, Oct 17, 2009 at 10:22 PM, StarWing <> wrote:
    > okay, I think somethings do....while is useful, but why python didn't
    > have it?


    For simplicity of syntax and less duplication among the basic
    syntactic constructs.

    > 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?


    It's essentially the same:

    while True:
    ...
    if not cond: break

    This is considered idiomatic; and FWIW, I see do-while as having no
    significant advantage over this.

    Cheers,
    Chris
    --
    http://blog.rebertia.com
    Chris Rebert, Oct 18, 2009
    #2
    1. Advertising

  3. StarWing

    Chris Rebert Guest

    On Sat, Oct 17, 2009 at 10:34 PM, Chris Rebert <> wrote:
    > On Sat, Oct 17, 2009 at 10:22 PM, StarWing <> wrote:

    <snip>
    >> but in python, we only can:
    >> cond = 1
    >> while cond:
    >>    cond = 0
    >>    .....
    >>    if ....: cond = 1
    >>
    >> has any polite way to handle this?

    >
    > It's essentially the same:
    >
    > while True:
    >    ...
    >    if not cond: break


    Substituting in the appropriate conditional expression for cond of
    course (your use of cond for the flag caught me off guard).

    Cheers,
    Chris
    Chris Rebert, Oct 18, 2009
    #3
  4. StarWing

    StarWing Guest

    On 10月18æ—¥, 下åˆ1æ—¶36分, Chris Rebert <> wrote:
    > On Sat, Oct 17, 2009 at 10:34 PM, Chris Rebert <> wrote:
    > > On Sat, Oct 17, 2009 at 10:22 PM, StarWing <> wrote:

    > <snip>
    > >> but in python, we only can:
    > >> cond = 1
    > >> while cond:
    > >>    cond = 0
    > >>    .....
    > >>    if ....: cond = 1

    >
    > >> has any polite way to handle this?

    >
    > > It's essentially the same:

    >
    > > while True:
    > >    ...
    > >    if not cond: break

    >
    > Substituting in the appropriate conditional expression for cond of
    > course (your use of cond for the flag caught me off guard).
    >
    > Cheers,
    > Chris


    Thank you, this is nice than mine :)
    StarWing, Oct 18, 2009
    #4
  5. StarWing

    Lie Ryan Guest

    Chris Rebert wrote:
    > On Sat, Oct 17, 2009 at 10:22 PM, StarWing <> wrote:
    >> okay, I think somethings do....while is useful, but why python didn't
    >> have it?

    >
    > For simplicity of syntax and less duplication among the basic
    > syntactic constructs.


    Less language features means less decisions to make.
    Lie Ryan, Oct 18, 2009
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. GAP and Java

    , Dec 5, 2004, in forum: Java
    Replies:
    2
    Views:
    958
    Gordon Beaton
    Dec 6, 2004
  2. crispy
    Replies:
    6
    Views:
    478
    crispy
    Jul 4, 2003
  3. Wayfarer
    Replies:
    2
    Views:
    419
    Toby A Inkster
    Sep 30, 2003
  4. Nik Coughin

    Please, what is causing this gap?

    Nik Coughin, Dec 12, 2004, in forum: HTML
    Replies:
    8
    Views:
    384
    Nik Coughin
    Dec 12, 2004
  5. chlori

    Gap in IE, no gap in FF

    chlori, Jan 19, 2006, in forum: HTML
    Replies:
    1
    Views:
    446
    kchayka
    Jan 19, 2006
Loading...

Share This Page