foreach item coll [function] [arguments] (tab)statements (tab)...
Can be single line:
foreach(item coll [function] [arguments]) statements
item - variable that in each loop receives next item from coll collection. Type depends on other parameters.
coll - usually a collection of some kind.
function - a user-defined function that populates the item variable.
arguments - additional arguments for function.
foreach is similar to rep and for. It simplifies enumeration of items in collections of various kinds. Executes statements for each item in the collection.
Currently there are two predefined kinds of collections that may be used with foreach. Used without function.
If coll is string, in each loop is extracted next line and stored into item variable. The variable must also be string (str or lpstr).
If coll is a COM collection interface, in each loop is extracted next item and stored into item variable. Type of the variable must match type of collection elements, or can be VARIANT. The COM interface should be defined in a type library.
There is possibility to extend foreach. For example, enumerate windows, files, etc. Read more.
Use break to exit loop. Use continue to skip following statements.
foreach can be in other block (if, for, ...).
For each line: str s str lines="line1[]line2[][]line3" foreach s lines if(!s.len) continue out s For each COM object (enumerate environment variables): Wsh.WshShell shell._create VARIANT v foreach v shell.Environment out v