statements in control structures (Re: Conditional Expressions don't solve the problem)

Huaiyu Zhu huaiyu at gauss.almadan.ibm.com
Thu Oct 18 15:54:15 EDT 2001


On Thu, 18 Oct 2001 02:10:40 -0600, Andrew Dalke <dalke at dalkescientific.com>
wrote: 

>>- need two kinds of "break" (one impact "else" the other does not).

>- Really?  I thought 'break expression:' would be identical to
>    if expression:
>        break
>and wouldn't hit the else.  Neither does the existing else.
>So there are only two ways to write the same thing.

Well, I think you keep on missing one of the main point:  

A
while B; C1:
   D1
   if C2: break
   D2
else:
   E1
E2

has two exists: C1->E1, C2->E2.   This is not the same as 

A
loop:
   B
   if not C1: break
   D1
   if C2: break
   D2
else:
   E1
E2

where both C1 and C2 would lead to E2.  So you would have to write

A
loop:
   B
   if not C1:
      E1
      break
   D1
   if C2: break
   D2
E2

Or you have to enclose the whole thing in another function and use "return"
as the name of another "break".

That's why I ask you whether you think else-clause in while is completely
useless.  I'd agree that if not for the elif and the else-in-while the
changes would indeed be superfluous.

You could try to change the examples from the Python source distribution I
gave in another post to the loop-break style and see what they look like.
:-)


Huaiyu



More information about the Python-list mailing list