T3D/Scripters/T3D Scripters LogicalStatements

From TDN

Contents

If...Then

Switch

While Loop

For Loop

A for loop is a loop that usually contains a pre-defined number of how many iterations the loop should run. The loop will run until the condition evaluates to false.

The basic syntax in a for loop in TorqueScript is as follows:

for (start, condition, increment)
{
   // statements.
}

An actual code example would look like this:

for (%i = 0; %i < 10; %i ++)
{
   echo(%i);
}

see: while()

For Each

There is also a foreach loop that exists in TorqueScript. For each loops are like for loops, except iterations are controlled by the parser and not the programmer.

The basic syntax for a for each loop in TorqueScript is as follows:

foreach (%obj in Group)
{
   // statements
}

A code example:

foreach (%client in ClientGroup)
{
     echo(%client);
}