Re: Understanding while...else...

Discussion in 'Python' started by Oscar Benjamin, Jan 23, 2013.

  1. On 23 January 2013 11:03, René KlaÄan <> wrote:
    > On Wed, Jan 23, 2013 at 1:39 AM, Oscar Benjamin <> wrote:


    You missed off an important piece of context in your post:

    >> I think he meant that he would use the else clause more often if it
    >> had the semantics so that the two blocks below were equivalent:


    The key word in that sentence is "if".

    >> # Version 1
    >> while condition:
    >> # stuff
    >> else:
    >> # other stuff
    >>
    >> # Version 2
    >> if condition:
    >> while condition:
    >> # stuff
    >> else:
    >> # other stuff

    >
    > they wouldnt be equivalent if #staff in version did not cointain "break"
    > statement and this is common mistake


    I realise that they are not equivalent. My point was that some people
    expect, or would prefer, different behaviour so that those two *would*
    be equivalent (assuming that evaluating "condition" doesn't have side
    effects).


    Oscar
    Oscar Benjamin, Jan 23, 2013
    #1
    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. Gergely Kontra
    Replies:
    16
    Views:
    230
    Devin Mullins
    Sep 20, 2005
  2. Terry Reedy

    Understanding while...else...

    Terry Reedy, Jan 22, 2013, in forum: Python
    Replies:
    0
    Views:
    110
    Terry Reedy
    Jan 22, 2013
  3. Ethan Furman

    Re: Understanding while...else...

    Ethan Furman, Jan 22, 2013, in forum: Python
    Replies:
    0
    Views:
    115
    Ethan Furman
    Jan 22, 2013
  4. Terry Reedy

    Re: Understanding while...else...

    Terry Reedy, Jan 22, 2013, in forum: Python
    Replies:
    0
    Views:
    128
    Terry Reedy
    Jan 22, 2013
  5. Oscar Benjamin

    Re: Understanding while...else...

    Oscar Benjamin, Jan 23, 2013, in forum: Python
    Replies:
    0
    Views:
    97
    Oscar Benjamin
    Jan 23, 2013
Loading...

Share This Page