<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.ice-online.com/index.php?action=history&amp;feed=atom&amp;title=FOREACH</id>
	<title>FOREACH - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.ice-online.com/index.php?action=history&amp;feed=atom&amp;title=FOREACH"/>
	<link rel="alternate" type="text/html" href="https://wiki.ice-online.com/index.php?title=FOREACH&amp;action=history"/>
	<updated>2026-04-19T11:59:01Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.34.1</generator>
	<entry>
		<id>https://wiki.ice-online.com/index.php?title=FOREACH&amp;diff=821&amp;oldid=prev</id>
		<title>ConvertBot: implements a foreach iteration loop within a macro</title>
		<link rel="alternate" type="text/html" href="https://wiki.ice-online.com/index.php?title=FOREACH&amp;diff=821&amp;oldid=prev"/>
		<updated>2020-04-27T22:05:08Z</updated>

		<summary type="html">&lt;p&gt;implements a foreach iteration loop within a macro&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;implements a foreach iteration loop within a macro&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;ITEM&amp;gt;  Result label to hold item&lt;br /&gt;
&amp;lt;FUNC&amp;gt;  Function type [INDF,INFILE,INLIST,INSIZE,INTABLE,INTF]&lt;br /&gt;
&amp;lt;IN&amp;gt;    Variable containing input values&lt;br /&gt;
&lt;br /&gt;
A FOREACH-ENDFOR combination is used in a macro to loop through each&lt;br /&gt;
value in a set defined by either a List, Table, or File.&lt;br /&gt;
&lt;br /&gt;
Each pass through the loop, the result &amp;lt;ITEM&amp;gt; will contain the next&lt;br /&gt;
member of the set.&lt;br /&gt;
&lt;br /&gt;
Modifiers may be added to the end of the &amp;lt;FUNC&amp;gt; name to modify behavior.&lt;br /&gt;
For example, INTABLE/V for key values instead of key names.&lt;br /&gt;
&lt;br /&gt;
There are no restrictions nesting FOREACH loops.&lt;br /&gt;
&lt;br /&gt;
Since 2.5.0 the generic IN function has been added that can iterate over&lt;br /&gt;
a large number of Java objects, including:&lt;br /&gt;
  o java.util.Map          (includes Table, Hashtable, HashMap, ...)&lt;br /&gt;
  o java.util.Collection   (includes List, Vector, LinkedList, ...)&lt;br /&gt;
  o java.util.Iterator     (any implementation of the Iterator interface)&lt;br /&gt;
  o java.util.Enumeration  (any implementation of the Enumeration interface)&lt;br /&gt;
  o java.lang.Object[]     (any generic Java array)&lt;br /&gt;
  o nxm.sys.lib.Data       (the values in a Data object via Data.toVector())&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
  o Using IN for a Map iterates over the keys in the Map, using IN/V&lt;br /&gt;
    iterates over the values in the Map.&lt;br /&gt;
  o The IN function only supports /REV when using an Object[].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
FUNCTIONS:&lt;br /&gt;
  INDF      - Each element in a Midas data file&lt;br /&gt;
  INFILE    - Alias for INDF&lt;br /&gt;
  INLIST    - Each element in a comma separated list&lt;br /&gt;
  INSIZE    - Iterate for IN=&amp;lt;size&amp;gt;&lt;br /&gt;
  INTABLE   - Each key in a table or KeyVector&lt;br /&gt;
  INTABLE/V - Each value in a table or KeyVector&lt;br /&gt;
  INTF      - Each line in a text file&lt;br /&gt;
  INKW      - Each keyword in a Midas file with scope&lt;br /&gt;
  IN        - Each item in a Java object (see above)&lt;br /&gt;
  IN/V      - Each value in a Java Map object (see above)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
EXAMPLES:&lt;br /&gt;
  1. Erase all files whose names are in a given data file&lt;br /&gt;
        foreach name INDF mydatafile&lt;br /&gt;
          erase name&lt;br /&gt;
        endfor&lt;br /&gt;
&lt;br /&gt;
  2. Iterate through each item in a LIST&lt;br /&gt;
        foreach area INLIST &amp;quot;MYOPT,SP,GEO,SYS&amp;quot;&lt;br /&gt;
          configure c ^area&lt;br /&gt;
        endfor&lt;br /&gt;
&lt;br /&gt;
  3. Iterate through each element in a FILE (0 to SIZE-1)&lt;br /&gt;
        foreach offset INSIZE FILE(fftdemo).size&lt;br /&gt;
          say &amp;quot;Data at ^offset is ^{FILE(fftdemo).data(offset)}&amp;quot;&lt;br /&gt;
        endfor&lt;br /&gt;
&lt;br /&gt;
  4. Iterate through each KEY in a table&lt;br /&gt;
        foreach key INTABLE msg.data&lt;br /&gt;
          say &amp;quot;Key ^key = ^msg.data.^key&amp;quot;&lt;br /&gt;
        endfor&lt;br /&gt;
&lt;br /&gt;
  5. Iterate through each KEY in a KeyVector. Produces values for layName of&lt;br /&gt;
     GRID, WORLD and CITIES&lt;br /&gt;
        plot/bg world|cities&lt;br /&gt;
        foreach layName INTABLE reg.PLOT.layers&lt;br /&gt;
          say &amp;quot;Layer name = ^layName&amp;quot;&lt;br /&gt;
        endfor&lt;br /&gt;
&lt;br /&gt;
  6. Iterate through each VALUE (KEY=VALUE) in a table&lt;br /&gt;
        foreach val INTABLE/V msg.data&lt;br /&gt;
          say &amp;quot;Value = ^val&amp;quot;&lt;br /&gt;
        endfor&lt;br /&gt;
&lt;br /&gt;
  7. Iterate through each line in a TEXT file&lt;br /&gt;
        foreach line INTF mytextfile&lt;br /&gt;
          say &amp;quot;Next Line is: ^line&amp;quot;&lt;br /&gt;
        endfor&lt;br /&gt;
&lt;br /&gt;
  8. Iterate through each keyword in a Data file&lt;br /&gt;
        foreach kwi INKW env.hwfile /scope=tag=alias&lt;br /&gt;
          say &amp;quot;Next Key: ^kwi.name  Value: ^kwi.value&amp;quot;&lt;br /&gt;
        endfor&lt;br /&gt;
&lt;br /&gt;
  9. Iterates over a Java Vector&lt;br /&gt;
        new java.util.Vector vect&lt;br /&gt;
        ...&lt;br /&gt;
        foreach val IN vect&lt;br /&gt;
          say &amp;quot;val = ^{val}&amp;quot;&lt;br /&gt;
        endfor&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Switches:&lt;br /&gt;
  /REV   - process elements in reverse order (not implemented)&lt;br /&gt;
  /SCOPE - For INKW only.  Sets the SCOPE. See KEYWORD command.&lt;br /&gt;
  /SORT  - process elements in sorted order (applies only to Tables)&lt;br /&gt;
  /VAL   - Same as INTABLE/V or IN/V&lt;br /&gt;
&lt;br /&gt;
SEE ALSO:  ENDFOR, BREAK, KEYWORD&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:NXM_Explain]]&lt;/div&gt;</summary>
		<author><name>ConvertBot</name></author>
		
	</entry>
</feed>