FOR
Syntax
FOR (Index, Start, Finish, Loop Body)
Description
The FOR function loops through a series of values.
Parameters
| Parameter | Description |
|---|---|
|
Index |
The name of the variable that holds the index number. |
|
Start |
The index value at which to start the loop. |
|
Finish |
The index value at which to finish the loop. |
|
Loop Body |
The action to take at the current index. |
Example
The following formula
raises a base to an integral exponent without using the ^ operator:
IF(EXPONENT <> TRUNC(EXPONENT), RETURN(0.0));
SET(&Result, 1);
FOR(&Index, 1, ABS(EXPONENT),
SET(&Result, &Result * BASE));
IF(EXPONENT >= 0, &Result, 1 / &Result)
In this formula, the FOR function sets the specified variable to each value at the beginning of the loop, counting up if Finish is greater than Start, and counting down if Start is greater than Finish.