Re: Understanding while...else...

2013-01-23 Thread Terry Reedy
On 1/22/2013 7:39 PM, Oscar Benjamin wrote: On 22 January 2013 23:41, Terry Reedy wrote: On 1/22/2013 3:09 PM, Ethan Furman wrote: On 01/22/2013 09:44 AM, Terry Reedy wrote: [SNIP] The else clause is executed if and when the condition is false. Now use a real Python while statement to do

Re: Understanding while...else...

2013-01-23 Thread Terry Reedy
On 1/22/2013 1:15 PM, Jean-Michel Pichavant wrote: - Original Message - Several people have trouble understanding Python's while-else and for-else constructs. It is actually quite simple agreed on the last part. [snip long story] Did you just try to make it simple by showing the comp

Re: Understanding while...else...

2013-01-23 Thread Jean-Michel Pichavant
- Original Message - > Several people have trouble understanding Python's while-else and > for-else constructs. It is actually quite simple agreed on the last part. [snip long story] Did you just try to make it simple by showing the compiled code ? I'm quite not sure about that... JM

Re: Understanding while...else...

2013-01-23 Thread Oscar Benjamin
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 equiv

Re: Understanding while...else...

2013-01-23 Thread René Klačan
> > # 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 On Wed,

Re: Understanding while...else...

2013-01-23 Thread René Klačan
they wouldnt be equivalent if #staff in version 1 did not cointain "break" statement and this is common mistake On Wed, Jan 23, 2013 at 1:39 AM, Oscar Benjamin wrote: > On 22 January 2013 23:41, Terry Reedy wrote: > > On 1/22/2013 3:09 PM, Ethan Furman wrote: > >> > >> On 01/22/2013 09:44 AM, Te

Re: Understanding while...else...

2013-01-22 Thread Oscar Benjamin
On 22 January 2013 23:41, Terry Reedy wrote: > On 1/22/2013 3:09 PM, Ethan Furman wrote: >> >> On 01/22/2013 09:44 AM, Terry Reedy wrote: >>> [SNIP] >>> The else clause is executed if and when the condition is false. >>> Now use a real Python while statement to do the *same >>> thing*. >>> >>> whi

Re: Understanding while...else...

2013-01-22 Thread Terry Reedy
On 1/22/2013 3:09 PM, Ethan Furman wrote: On 01/22/2013 09:44 AM, Terry Reedy wrote: Several people have trouble understanding Python's while-else and for-else constructs. It is actually quite simple if one starts with if-else, which few have any trouble with. Start with, for example if n > 0:

Re: Understanding while...else...

2013-01-22 Thread Ethan Furman
On 01/22/2013 09:44 AM, Terry Reedy wrote: Several people have trouble understanding Python's while-else and for-else constructs. It is actually quite simple if one starts with if-else, which few have any trouble with. Start with, for example if n > 0: n -= 1 else: n = None The else clau