Author Topic: Looping?  (Read 1750 times)

0 Members and 1 Guest are viewing this topic.

Offline Patrick

Looping?
« 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




Offline Joel

Re:Looping?
« Reply #1 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
« Last Edit: October 28, 2002, 07:33:19 PM by Joel »

Offline Nick Sonneveld

Re:Looping?
« Reply #2 on: October 28, 2002, 07:55:27 PM »
I'm working on it. (switches, fors, whiles.. that stuff)

- Nick
Nick Sonneveld  |  AGI Dev  |  NAGI

Offline Jelle

Re:Looping?
« Reply #3 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?
Politics is supposed to be the second-oldest profession. I have come to realize that it bears a very close resemblance to the first.

Offline Joel

Re:Looping?
« Reply #4 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.


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

Page created in 0.043 seconds with 21 queries.