Next: , Previous: Error, Up: Statements



6.11.7 The foreach Statement

You may wish to manipulate all elements of a list or a record sequentially in one rule path. For this purpose, the foreach statement was introduced. It has the following format:

     foreach $var in expr:
       statements
     end foreach;

Sequentually, $var is assigned a number of values, depending on the type of expr, and the statement sequence statements is executed for each of those assignments. Every time the statements are being walked through, the variable $var is defined again. Its scope is the block statements.