Promotic

For Each...Next - statement of language VBScript

Description:
Repeats a group of statements for each item in an array or collection (Collection)
Syntax:
For Each element In group
  [statements]
  [Exit For]
  [statements]
Next [element]


element Variable used to iterate through the items of the collection or array.
group Name of an object collection or array.
statements One or more statements that are executed on each item in group.
Note:
The For Each block is entered if there is at least one item in group. If the loop has been entered, then all the statements in the loop are executed for the first item in group. If there are more items in group, then the statements in the loop continue to execute for each item. If there are no more items in group, then the loop is exited and execution continues with the statement following the Next statement.
The 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. The 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.
You can nest For Each...Next loops by placing one For Each...Next loop within another. However, each loop element must be unique.

Note: If you omit item in a Next statement, execution continues as if you had included it. If a Next statement is encountered before its corresponding For statement, then an error occurs.
See also:
Example:
Dim fso, f, f1, fc, s
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(folderspec)
Set fc = f.Files
For Each f1 in fc
  s = s & f1.name
  s = s & "<br>"
Next
PROMOTIC 9.0.27 SCADA system documentation MICROSYS, spol. s r.o.

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