Siebel eScript Language Reference > Siebel eScript Language Overview > Siebel eScript Statements >
for Statement
The for statement repeats a series of statements a fixed number of times. Syntax
for ( [var] counter = start; condition; increment ) { statement_block; }
|
|
counter |
A numeric variable for the loop counter |
start |
The initial value of the counter |
condition |
The condition at which the loop should end |
increment |
The amount by which the counter is changed each time the loop is run |
statement_block |
The statements or methods to be executed |
Usage
The counter variable must be declared with var if it has not already been declared. Even though it is declared in the for statement, its scope is local to the whole function that contains the for loop. First, the expression counter = start is evaluated. Then condition is evaluated. If condition is true or if there is no conditional expression, the statement is executed. Then the increment is executed and condition is reevaluated, which begins the loop again. If the expression is false, the statement is not executed, and the program continues with the next line of code after the statement. Within the loop, the value of counter should not be changed in ways other than being incremented on each pass through the loop. Changing the counter in other ways makes your script difficult to maintain and debug. A for statement can control multiple counters in a loop. The various counter variables and their increments must be separated by commas. For example: for (var i = 1, var j = 3; i < 10; i++, j++) var result = i * j;
Example
For an example of the for statement, see eval() Method. See Also
do...while Statement while Statement
|