up previous next
foreach

loop command

Syntax
foreach  X  in  L  do  CMDS  endforeach
where 
    X  
 is a dummy variable, 
    L  
 is a LIST

Description
The dummy variable X is assigned the value of each component of L in turn. After each assignment the command sequence CMDS is executed.

Example
/**/  foreach N In 1..10 Do  -- NOTE: 1..10 gives the list [1,...,10].
/**/    print N^2, " ";
/**/  endforeach;
1 4 9 16 25 36 49 64 81 100

/**/  Use R ::= QQ[x,y,z];
/**/  F := x^2*y + 3*y^2*z - z^3;
/**/  J := [deriv(F, X) | X In indets(R)];
/**/  J;
[2*x*y, x^2 +6*y*z, 3*y^2 -3*z^2]

/**/  Foreach X In J Do
/**/    PrintLn X^2;
/**/  EndForeach;
4*x^2*y^2
x^4 +12*x^2*y*z +36*y^2*z^2
9*y^4 -18*y^2*z^2 +9*z^4

See Also