Language Reference/Terms/Foreach

 : foreach  do  end foreach

Consider the schematic foreach term:

foreach Gen do Body end foreach

Gen is (typically) a nondeterm term. Body is evaluated for each solution of Gen. If/when Gen fails the foreach</vp>-term succeeds without evaluating Body</vp>. Body must be procedure</vp> (or erroneous</vp>). Gen</vp> and Body</vp> are both.

The schematic foreach term resembles a fail loop:

Gen, Body, fail

The main (and important) difference is that a foreach</vp>-term succeeds after the iteration, whereas a fail loop fails. As a result foreach</vp>-terms can be followed by other terms and they can be properly nested.