Description:
Repeats a group of statements a specified number of times.
Syntax:
for (statement1; statement2; statement3)
{
[
statements]
[
break;]
}
The
for statement consists of three parts separated by semicolon:
statement1 - Specifies the initial numeric value of the variable used as cycle counter. For example:
statement2 - Logical expression that is evaluated at the beginning of each cycle iteration. If the expression returns
true, then the iteration is completed, otherwise the cycle is exited.
It is usually a simpe test whether the cycle counter is within the defined range. For example:
i < 20
statement3 - This statement is executed at the end of each iteration. It is usually an incrementation (or decrementation) of corresponding cycle variable. For example:
i++
Note:
break statement can be used inside a loop to provide an alternate way to exit.
In the VBScript language is used the statement for this purpose
For...Next.
Example1:
JavaScriptSelect and copy to clipboard
var iRow;
for (iRow = 0; iRow < 2; iRow++)
{
// test
Pm.Debug("iRow = " + iRow);
}
Example2:
You can nest For...Next loops by placing one For...Next loop within another. Give each loop a unique variable name as its counter. The following construction is correct:
JavaScriptSelect and copy to clipboard
var iRow, iCol, iItem;
for (iRow = 1; iRow < 3; iRow++)
{
for (iCol = 1; iCol < 3; iCol++)
{
for (iItem = 1; iItem < 3; iItem++)
{
// test
Pm.Debug("iRow = " + iRow + ", iCol = " + iCol + ", iItem = " + iItem);
}
}
}