control structures (was "Re: Sins")
skaller
skaller at maxtal.com.au
Sat Jan 8 08:55:15 EST 2000
Phil Jensen wrote:
> I forget if I posted this before, but what I'd like to
> see is the Zahn construct discussed in Knuth's article -
> Pythonically:
>
> loop until "element found" or "search failed":
> ...
> if blah1 == blah2:
> "element found"
> ...
> when "element found":
> ...
> when "search failed":
> ...
I've read that article too, and tend to agree.
How about:
with Found, NotFound:
initialiser ...
loop:
loop body ...
signal Found ..
case Found:
print "found it"
case NotFound:
print "couldn't find it"
finally:
cleanup ..
Semantics: each label in the 'with' part must be
given as a case. No exit from the loop exists,
except for the listed cases.
Implementation:
with:
class Found: pass
class NotFound: pass
..
do:
try:
try:
while 1:
.. raise Found
except Found: ...
finally: ..
> IMHO, "break 3" would be awful.
Agree. Shades of Tcl. :-(
--
John (Max) Skaller, mailto:skaller at maxtal.com.au
10/1 Toxteth Rd Glebe NSW 2037 Australia
homepage: http://www.maxtal.com.au/~skaller
voice: 61-2-9660-0850
More information about the Python-list
mailing list