break LABEL vs. exceptions + PROPOSAL

Gareth McCaughan Gareth.McCaughan at pobox.com
Thu Sep 2 16:23:22 EDT 1999


Evan Simpson wrote:

> try:
>   ...
>   break <string>, <value>
>   ...
> continue <string1>, <name-binding-list1>:
>   <suite1>
> continue <string2>, <name-binding-list2>:
>   <suite>
> 
> The first argument to "break" and "continue" is required to be a string, and
> each "break" string is required to match a string in a containing try's
> "continue".  This makes it clear that we're breaking out of the suite rather
> than raising an exception, and could be implemented efficiently and
> trivially with jump, load, and store bytecodes.

I've been looking for a language that does this ever since I read
Knuth's paper "Structured programming with go to statements"[1]
(reprinted in his book "Literate Programming"). It would be nice
(though clearly entirely unnecessary) to allow "continue" handlers
attached directly to a loop, too, since that's probably the
commonest situation in which you need them.

I don't like the name "continue", though, especially in view of
the connection with loops. "exit"? "leave"? "when"?


[1] Knuth didn't invent the construction; I forget who did. But
    this paper is where I read about it first.

-- 
Gareth McCaughan  Gareth.McCaughan at pobox.com
sig under construction




More information about the Python-list mailing list