Replace for Goto

Helmut Jarausch jarausch at skynet.be
Thu May 29 07:41:02 EDT 2003


Gerhard Häring wrote:
> Dvm5 wrote:
> 
>> I'm used to Basic. There is a Goto/Label command, you put goto where
>> you want it to come from and label where you want it to go. Simple.
>> How can I do this in Python?
> 
> 
> You can't. This is a feature, not a bug ;-) With the control structures 
> Python offers (for loops, while loops, functions, exceptions), GOTO is 
> not necessary.

with one notable exception. Python is missing a labled break statement
like in Perl. This is important if one wants to break out of a deeply
nested loop. The only way I see in Python is to (mis)use an exception
for that purpose. In Perl the header of a loop may bear a label and
if that is referenced by a break statement, that loop is terminated.
Python doesn't seem to have an equivalent for that.


-- 
Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany





More information about the Python-list mailing list