foreach statement

Purpose: The statements are executed once for each value of var which ranges from m to n(including m and n) as specified by the user.The value of var can be accessed within the body of the loop by using $var.

Status: Done. Nesting is not supported at the moment.

Syntax:

  foreach var m:n
  ...
  end

Let's see some examples based on this command.

Example 1:

   foreach a 1:5
      echo $a
   end

Output:

   
  gnucap> 1
          2
          3
          4
          5

Example 1:

   param a=2
   foreach val 2:4
      eval($val+a)
   end

Output:

   gnucap> (2+a)=4.
           (3+a)=5.
           (4+a)=6.