Community

AGI Programming => Mega Tokyo AGI Archive => Topic started by: Patrick on October 28, 2002, 07:26:25 PM

Title: Looping?
Post by: Patrick on October 28, 2002, 07:26:25 PM
Probabally a dumb question...i am wondering if AGI has any type of looping like a

Do While

While Wend...

You get the picture....


SMG240
Title: Re:Looping?
Post by: Joel on October 28, 2002, 07:32:38 PM
The interpreter of course is constantly running in a loop, but if you want to loop during a cycle, you'll have to use labels and gotos for now (until the language is extended to add more stuff).

Code: [Select]
WhileTest:
if (x < 10)
{
  goto(WhileBody);
}
goto(WhileEnd);

WhileBody:
x += 1;
goto(WhileTest);

WhileEnd:
if (said("look")) // ... and so on

The above code is equivalent to this C-like code:
Code: [Select]
while (x < 10)
{
  x++;
}

if (said("look")) // ... and so on
Title: Re:Looping?
Post by: Nick Sonneveld on October 28, 2002, 07:55:27 PM
I'm working on it. (switches, fors, whiles.. that stuff)

- Nick
Title: Re:Looping?
Post by: Jelle on October 29, 2002, 04:39:46 AM
Isn't that the same as:

Code: [Select]
WhileTest:
if (x < 10) {
  x += 1;
  goto(WhileTest);
} else {
  goto(WhileEnd);
}

WhileEnd:
if (said("look")) // ... and so on

Why do you use the WhileBody? Just because then you can see what the test is, what the body is and what the loop is, or is there another reason?
Title: Re:Looping?
Post by: Joel on October 29, 2002, 11:23:53 AM
yeah, I think it is the same. no, there's no particular reason why I chose to write it like that other than to be as clear as possible about what's going on. Also, probably a little left over from a compiler's course I took where an if-else structure was implemented as a comparison and two jump instructions.