for - statement of language JavaScript

Repeats a group of statements a specified number of times.

for (statement1; statement2; statement3)





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:
var i=0
statement2 - Logical expression that is evaluated ata the beginning of each cycle iteration. If the expression returns true, then the iteration is completed, otherwise the cycle is exited.

It is usualy 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 usualy an incrementation (or decrementation) of corresponding cycle variable. For example:
break statement can be used inside a loop to provide an alternate way to exit.
For similar purpose in the VBScript language is used the statement For...Next.
A simple cycle example. It dumps text i=1 and i=2 into the Debug_info item of the INFO system.
JavaScriptSelect and copy to clipboard

var i;
for (i = 0; i < 2; i++)
  Pm.Debug("i=" + i);
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 i, j, k;
for (i = 1; i < 3; i++)
  for (j = 1; j < 3; j++)
    for (k = 1; k < 3; k++)
      Pm.Debug("i=" + i + ", j=" + j + ", k=" + k);
PROMOTIC 8.3.26 SCADA system documentation - MICROSYS, spol. s r.o.

Send page remarkContact responsible person
© MICROSYS, spol. s r. o.Tavičská 845/21 703 00 Ostrava-Vítkovice