for-else

Terry Reedy tjreedy at udel.edu
Mon Mar 10 23:22:37 EDT 2008


"rockingred" <willsteve2003 at yahoo.ca> wrote in message 
news:7a6555fa-819a-41c0-befe-ee0123272b31 at 59g2000hsb.googlegroups.com...
On Mar 8, 4:15 pm, "Terry Reedy" <tjre... at udel.edu> wrote:
> If the sense of else were reversed, one would have to write the clumbsier
>
> complete = True # though false at this point
> while loop_condition:
> <loop statements>
> if break_condition:
> complete = False
> break
> <more loop stuff>
> else:
> <break-only statements>
> if complete:
> <completion-only statements>
>
> Terry Jan Reedy

Terry, instead of using "complete = True" and setting it to false on
failure, why not set "loop_completed = False" and set it to True if
the break condition is met?
[OE not quoting properly]
=====================
Because completion is False when broken?  Actually, I am not sure what you 
mean without seeing the snippet rewritten.  Certainly, one could set 
'broken=False' at top (tho not true) and 'broken = True' before breaking 
and test for 'not broken' at end, but that is not an improvement.

tjr






More information about the Python-list mailing list