CoCoA:Foreach
From ApCoCoAWiki
Foreach
loop command
Description
The dummy variable X is assigned the value of each component of L in
turn. After each assignment the command sequence C is executed.
Note: don't forget to capitalize In.
Example
Foreach N In 1..10 Do -- Note: 1..10 gives the list [1,...,10]. Print N^2, <quotes> </quotes>; EndForeach; 1 4 9 16 25 36 49 64 81 100 ------------------------------- Use R ::= Q[x,y,z]; F := x^2y + 3y^2z - z^3; J := [Der(F,X) | X In Indets()]; -- the Jacobian for F J; [2xy, x^2 + 6yz, 3y^2 - 3z^2] ------------------------------- Foreach X In J Do -- square each component of the Jacobian PrintLn X^2; EndForeach; 4x^2y^2 x^4 + 12x^2yz + 36y^2z^2 9y^4 - 18y^2z^2 + 9z^4 -------------------------------
Syntax
Foreach X In L Do C EndForeach where X is a dummy variable, L is a list, and C is a sequence of commands.
<type>programming</type> <type>loops</type>