Previous Next        Current Page: NeXtMidas Training / Macros - Part 1 (Basics) / Loops and Control Structures / Loops / FOREACH
back
Start Here   
Background   
Common Midas Concepts   
Getting Started - Part 1   
Getting Started - Part 2   
Working with Files   
Option Trees   
Macros - Part 1 (Basics)   
   + Macro Basics   
   - Loops and Control Structures   
      - IF   
         - Tests   
         - IF (Block)   
         - IF (One-Line)   
         - IF (Quick Check)   
      - Loops   
         - DO   
         - LOOP   
         - WHILE   
         - FOREACH   
         - BREAK and CONTINUE   
         - FORALL   
         - Summary   
      - GOTO and LABEL   
      - Lab 1 - Macro Control   
         - Instructions   
         - Solution   
      - Lab 2* - Macro Control   
         - Instructions   
         - Solution   
   + Procedures and Subroutines   
   + Pipes in a Macro   
   + Messages in a Macro   
Macros - Part 2 (Graphics)   
NetBeans - Part 1 (Setup)   
NetBeans - Part 2 (GUIs)   
NetBeans - Part 3 (Profiler)   
Eclipse - Part 1 (Setup)   
Eclipse - Part 2 (GUIs)   
Primitives   
WebStart   
Maps & Imagery   
X-Midas Interoperability   
RMIF & Remoting   
Installing NeXtMidas   
Support & Maintenance   
File Handlers   


  • 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/VEach 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 (Since NeXtMidas 2.5.0).

  • 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())

back