For Each...Next
- Updated2024-09-12
- 1 minute(s) read
VBScript Language Directory > Control Structures > For Each...Next
For Each...Next
Use this control structure to repeat statements for each element of a group, which is an Object collection or an array. Use this kind of repetition especially when you do not know how many elements are in such a group.
Do Each Element in Group [Statements] Next [Element]
| Element | A variable to run through all elements of a group. |
| Group | A group that consists of an object collection or an array. |
| Statements | One or more statements that DIAdem repeats for every element in the group. |
The following example runs through all elements of the asColors array:
Dim asColors(3),sElement,sText asColors(0) = "red" asColors(1) = "green" asColors(2) = "blue" asColors(3) = "yellow" For Each sElement in asColors sText = sText & sElement & char(13) Next Call MsgBox(sText)
Related Topics
Do While...Loop | Do...Loop Until | Exit | For...Next | For Each...Next | If...Then...Else | Select Case...Case...End Select | While...Wend | With