FOR EACH

Action

Repeats a group of statements for each element in an array or collection.

 

Syntax

FOR EACH $element IN group

      statements

NEXT

 

FOR EACH loops can be nested as many times as memory allows.

 

Parameters

Element

Variable used to iterate through the elements of the collection or array..

Group

Name of an object collection or array.

 

Remarks

The For Each block is entered if there is at least one element in group. Once the loop has been entered, all the statements in the loop are executed for the first element in group. As long as there are more elements in group, the statements in the loop continue to execute for each element. When there are no more elements in group, the loop is exited and execution continues with the statement following the Next statement.

 

Examples

Dim $MyArray[10]

For Each $Element In $MyArray

   ? $Element

Next

 

$Root = GetObject( "LDAP://localhost" )

For Each $Obj in $Root

   ? $Obj.name

Next