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.


for ( [var] counter = start; condition; increment )



A numeric variable for the loop counter


The initial value of the counter


The condition at which the loop should end


The amount by which the counter is changed each time the loop is run


The statements or methods to be executed


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;


For an example of the for statement, see eval() Method.

See Also

do...while Statement
while Statement

Siebel eScript Language Reference