PEP: statements in control structures

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


On Thu, 18 Oct 2001 12:42:10 +0300, CpJohnson at edgars.co.za
<CpJohnson at edgars.co.za> wrote: 

>Sorry to jump in at this late stage.  In the previous example there two two
>exits from the loop.
>The while statement already defines two exits, a) the controling expression
>returns false and, b) the break.
>So what's wrong with:-
>
>x = next()
>while not x.is_end:
>    y = process(x)
>    if y.is_what_we_are_looking_for(): break
>    x = next()
>else:
>    raise "not found"


Glad you observed the two-exit issue.  But 


    6.5. Repeat action before and after loop:

                line = file.readline()
                while line:
                    do_something()
                    line = file.readline()

        This is a maintenance liability - it is easy to go out of sync.
        This does not apply to the "if" structure, either.


Huaiyu



More information about the Python-list mailing list