Community
AGI Programming => Mega Tokyo AGI Archive => Topic started 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
-
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).
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:
while (x < 10)
{
x++;
}
if (said("look")) // ... and so on
-
I'm working on it. (switches, fors, whiles.. that stuff)
- Nick
-
Isn't that the same as:
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?
-
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.