While/Until-Statement


while expression { }
while (expression) statement;
statement while expression;

The while-loop evaluates the conditional expression expr and continues to execute the block of code while it is true (non-zero). When it is false, the code is skipped and execution continues. The keyword until can be substituted to mean "while not."

Do While/Until-Statement


do { } while expression;
do statement while expression;

Same as a while- or until-loop, but tests after the code has been executed.

For-Statement


for initialization; condition; step { }
for (initialization; condition; step) { }
for (initialization; condition; step) statement;

The initialization is carried out once, the condition is tested and if it is true, the body is executed followed by the step statement. And then the condition is tested again, etc. All of the expressions are optional, and if none are used, the loop will be infinite.

C-programmers should note that this for-loop restricts the initialization-expression to assignment statements and local variable declarations, and the step to assignment statements (including the increment- and decrement-statements) only.

See Also...

Loop-Statement


     loop { }
     loop statement;

Since infinite-loops, loops that execute forever, are such a worthwhile idiom in the AGAST Script Language, there is a special statement just for it, and a couple important provisos attached.

First, a loop must somehow delay for at least one cycle to return control to the interpreter, or the game will seem to freeze while the script executes forever. This can be done with the delay statement, or by calling any function or script which delays for any number of cycles.

Second, even though there is no way for such a loop to terminate by itself, there are a few other ways:

  • A nested return-statement will return from the script the loop is inside.
  • A nested finish-function will cause the event the loop is inside to finish.
  • If the event's killOnExit property is set to true, the interpreter will kill the event when the scene is over.
  • The event could be killed by another script with the killEvents function.
See Also...