GOTO w/ Python?

John Roth johnroth at ameritech.net
Thu Jun 20 07:11:55 EDT 2002


"Max M" <maxm at mxm.dk> wrote in message news:3D11A21D.9010809 at mxm.dk...
> Michael Hudson wrote:
>  > "John Roth" <johnroth at ameritech.net> writes:
>  >
>  >
>  >>There's no equivalent of a goto command in Python, for good reason,
>  >>which I won't repeat here. Prof. Djikstra did it very well in 1974,
>  >>in his letter "Goto Considered Harmful."
>  >
>  >
>  > There are also technical difficulties implementing it (the
>  > blockstack), or I'd have probably done goto functionality in
>  > bytecodehacks :)
>
>
> What do you mean???
>
>
> Goto's are simple ;-)
>
>
> def goto(lable):
>      lable()
>
>
> def start():
>
>      print 'starting'
>      goto(lable2)
>
> def lable1():
>
>      print 'at lable 1'
>      goto(stop)
>
> def lable2():
>
>      print 'at lable 2'
>      goto(lable1)
>
> def stop():
>      print 'stopping'
>
> goto(start)
>
>  >>> starting
>  >>> at lable 2
>  >>> at lable 1
>  >>> stopping

Those aren't goto's in the classical sense. For a real goto,
you need to think assembler: if it's a statement anywhere,
you can branch to it, and who cares about the execution
history! Having the compiler manage your flow control is
for sissys!

John Roth
>





More information about the Python-list mailing list