Looping?

smartguy240 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
Joel 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

sonneveld I'm working on it. (switches, fors, whiles.. that stuff)

- Nick
jelleghys 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?
Joel 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.