[Python-ideas] try-else without except or finally

Terry Reedy tjreedy at udel.edu
Fri Nov 11 00:26:47 CET 2011


On 11/10/2011 5:21 PM, Matt Joiner wrote:
> Your examples of else with loops are missing the extra behaviour on
> break?

I omitted 'break' as not relevant to the particular points I was aiming 
at. To add it in:

while c:
   x
   if d: break
else:
   y

in PythonGTL could be

label start_loop
if c:
   x
   if d: goto after_loop
   goto start_loop
else:
   y
label after_loop

> This is where the real value is in this usage.

Yes, 'break' is the main motivation for 'while...else'.
Return and raise (explicit or otherwise) also break the loop. But since 
they raise stylistic preference issues, I won't go into them here.

-- 
Terry Jan Reedy




More information about the Python-ideas mailing list