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

Andrew Dalke dalke at dalkescientific.com
Thu Oct 18 19:44:41 EDT 2001


Huaiyu Zhu wrote
>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.
   ...
>So you would have to write
>
>A
>loop:
>   B
>   if not C1:
>      E1
>      break
>   D1
>   if C2: break
>   D2
>E2

Ummm, yes.  So?  There's no duplicated code anywhere and while it
adds two lines of code in your minimal example, it's code that
helps with visual layout and doesn't have the ambiguous use
problems your proposal has.  (Ambiguous meaning when to use

  if stmt; x:
    y

over
  stmt
  if x:
    y

or
  stmt; if x:
    y

And you need to allow it in 'if' if you allow it in 'while',
else it's just one more rule to remember.



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

There are a few times when it's nice.  It's rare.  1% of while
loops use it in the std. library, and 50% were written by Tim Peters.

But I'm not arguing for or against while/else.  I'm arguing against
semicolon'ed statements.

>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.
>:-)

Done.
                    Andrew
                    dalke at dalkescientific.co






More information about the Python-list mailing list