goto

Steven D'Aprano steve at REMOVETHIScyber.com.au
Mon Jul 18 09:04:04 EDT 2005


On Mon, 18 Jul 2005 14:06:14 +0200, Mage wrote:

> Hayri ERDENER wrote:
> 
>>hi,
>>what is the equivalent of C languages' goto  statement in python?
>>best regards
>>  
>>
> You really shouldn't use goto.
> 
> Fortunately you can't.

Of course you can :-)

You can write your own Python interpreter, in Python, and add a goto to it.

You can use while or for loops, which are like goto, only they have all
the advantages and none of the disadvantages.

The same goes for continue and break, and try...except blocks: they
are safe, tame gotos, not wild, dangerous ones that are out of control. 

You can call functions. Functions are implemented at the machine code
level with the assembly language equivalent of a goto.

Or you can tell us what problem you want to solve with a goto, and we'll
tell you the proper way to solve it.


-- 
Steven.




More information about the Python-list mailing list