Re: Python Question
Sam, on host 24.61.194.240
Wednesday, June 19, 2002, at 16:49:36
Python Question posted by ang on Wednesday, June 19, 2002, at 14:34:06:
> How do I do the equivalent of the GOTO command?
There isn't one. Use of "goto" commands are big big no-nos, as use of them very quickly creates unreadable, unmaintainable code. If you use if, while, for, functions, and exceptions properly, you should never even encounter a situation where you'll *miss* the lack of a goto command.
The code fragment you quoted involves "exceptions," which is a controlled way for programs to stop execution and bail out when an error condition occurs. The gist of it is that if an exception is "raise"d during the execution of code in a "try" block, then the program jumps into an "except" block (following the "try" block) where the error handling can occur. So what happens in your quoted code is that a "label" exception is raised, and that causes it to be caught in the "except label:" block, so program execution leaps there.
For more information, see http://python.org/doc/current/ref/exceptions.html and http://python.org/doc/current/tut/node10.html.
|