Author Topic: Goto command  (Read 2131 times)

0 Members and 1 Guest are viewing this topic.

Offline Rich

Goto command
« on: February 05, 2004, 12:15:11 AM »
Does anyone know exactly how the Goto command works in AGI? I know that this command exists but I don't see any listing of it or its syntax in the AGI Help file. I don't need this command to make my game work, but it will immensely help with a sequence I am working on right now.

Thanks!



Offline beyond infinity

Re:Goto command
« Reply #1 on: February 05, 2004, 02:43:45 AM »
usually goto [label] is a unconditional branch to another position in program flow. It shall not be used, for it breaks the rules of Nassi Shneiderman. *gg*

Hence the third Commandmend of Kerrigan: "Thou Shalt Not Use the Goto!"
In the harbour they are safe
but this is not
what the ships are built for.
.:OSID:.

Offline Joel

Re:Goto command
« Reply #2 on: February 05, 2004, 02:55:05 AM »
I think it's something like:

Code: [Select]

   if (x == 5)
   {
       goto(MyLabel);
   }
   else
   {
        x = 5;
   }

MyLabel:

    // some code here
    goto(MyLabel);


Offline Brian Provinciano

Re:Goto command
« Reply #3 on: February 05, 2004, 04:04:29 AM »
The else is just a structured goto. Goto jumps from one point in the logic to another point. It is just like an if, but non conditional.

if(foo) {
 ... // if code
} else {
 ... // else code
}

Is the same as:

if(foo) {
  ... // if code
  goto else_done;
}
  ... // else code
else_done:


It can be used with if statements to make efficient (but unstructured) code that does funky things.

Offline Rich

Re:Goto command
« Reply #4 on: February 05, 2004, 05:57:38 AM »
Thanks, guys.

I had a bit or repeated code and I realized that ultimately a goto statement was the best way to go about it... even though I've tried to program for over a decade without ever using a goto again. Oh well. They're there for a reason.


SMF 2.0.19 | SMF © 2021, Simple Machines
Simple Audio Video Embedder

Page created in 0.035 seconds with 17 queries.