Promotic

For...Next - statement of language VBScript

Description:
Repeats a group of statements a specified number of times.
Syntax:

For counter=start To end [Step step]
  [statements]
  [Exit For]
  [statements]
Next

counter - Numeric variable used as a loop counter. The variable can't be an array item or an item of a user-defined type.
start - Initial value of the counter variable.
end - Final value of the counter variable.
step - Value the counter variable is changed each time through the loop.
If not set, then is 1.
statements - One or more statements between For and Next that are executed the specified number of times.
Note:
The step parameter can be either positive or negative. The value of the step parameter specifies loop processing as follows:
step >= 0: loop executes if counter <= end.
step < 0: loop executes if counter >= end.

If the loop starts then all statements in the loop have executed, and step is added to counter. At this point, either the statements in the loop execute again (based on the same test that caused the loop to execute initially), or the loop is exited and execution continues with the statement following the Next statement.

Tip: Changing the value of counter while inside a loop can make it more difficult to read and debug your script.

Exit For can only be used within a For Each...Next or For...Next control structure to provide an alternate way to exit. Any number of Exit For statements may be placed anywhere in the loop. Exit For is often used with the evaluation of some condition (e.g. If...Then...Else), and transfers control to the statement immediately following Next.

For similar purpose in the JavaScript language is used the statement for.
Example1:
A simple cycle example. It dumps texts i=1 and i=2 into the Debug item of the INFO system.
VBScriptSelect and copy to clipboard

Dim iRow
For iRow = 1 To 2
' test
Pm.Debug "iRow =" & iRow
Next
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:
VBScriptSelect and copy to clipboard

Dim iRow, iCol, iItem
For iRow = 1 To 3
For iCol = 1 To 4
For iItem = 1 To 5
' test
Pm.Debug "iRow = " & iRow & ", iCol = " & iCol & ", iItem=" & iItem
Next
Next
Next
PROMOTIC 9.0.27 SCADA system documentation MICROSYS, spol. s r.o.

Send page remarkContact responsible person
© MICROSYS, spol. s r.o.