Sun, 2 Dec 2001 09:53:43 +0100
On 0, Cow <email@example.com> wrote:
> I know in VB, you can make bookmarks such as:
> goto Cat
> msgbox "bla bla"
> msgbox "You are at Cat"
> and it will go to the "Cat" bookmark and perform the commands...
There is a problem with this construct. What will VB do *after* the commands
at the label Cat? It doesnn't go back to the command after the goto statement.
So the programs "jumps around" in a way that's hard to read - you can't see
at one glance that now it does that, then it does that, then it does that.
This sort of thing is why the goto statement is usually frowned upon in
programming languages - the classical text is from Edsger Dijkstra, called
"Go To statement considered harmful", from 1968 (!). Nothing is new in
programming :). Although it has been argued that there are situations in
which goto can be the right way to program something, Python is much too
clean to have the command.
> how can you do that in Python?
You put the commands in a function.
# There is no function 'message_box' without some preparation,
# this is just an example.
message_box("This is the function cat_messagebox.")
Now you can call cat_messagebox() from other places in your program - and
after doing it's thing, the program will always return to the command after
the function. This gives your program more structure.
(The paper is at <http://www.acm.org/classics/oct95/>)