Current Page: NeXtMidas Training Macros - Part 1 (Basics) Loops and Control Structures Loops FOREACH
- - | The `FOREACH` Loop: The `FOREACH` loop is used to iterate over all of the elements in a given object/file.
        FOREACH <item> <func> <in>
          ...
        ENDFOR
  - The `FOREACH` command supports a number of functions applicable to a variety of object/file types.
    Function | Iterate Over
    --- | ---
    `INDF` | Each element in a Midas DataFile
    `INFILE` | Alias for `INDF`
    `INLIST` | Each element in a comma separated list
    `INSIZE` | Iterate for `IN=<size>`
    `INTABLE` | Each key in a Table or KeyVector
    `INTABLE/V` | Each value in a Table or KeyVector
    `INTF` | Each line in a TextFile
    `INKW` | Each keyword in a DataFile with scope
    `IN` | Each item in a Java object (Collection, Map, array, etc.)
    `IN/V` | Each value in a Java Map object
    For example:
        foreach key INTABLE mytable
          say "Key ^key = ^mytable.^key"
        endfor

        foreach kwi INKW myfile.tmp /scope=tag=alias
          say "Next Key: ^kwi.name  Value: ^kwi.value"
        endfor
See the `FOREACH` explain file for more details.
Iteration
The generic `IN` and `IN/V` functions allow you to iterate over a large number of Java objects. java.util.Map (includes Table, Hashtable, HashMap, ...) java.util.Collection (includes List, Vector, LinkedList, ...) java.util.Iterator (any implementation of the Iterator interface) java.util.Enumeration (any implementation of the Enumeration interface) java.lang.Object[] (any generic Java array) nxm.sys.lib.Data (the values in a Data object via Data.toVector())