On Thu, 29 May 2014, Henrique Andrade wrote:
I'm a little bit confused about the use of lists with
foreach-loops.
Please take a look at the following code:
<hansl>
open australia.gdt
list L1 = PAU PUS
list L2 = E IAU
loop foreach i L1 --quiet
eval varname(i)
eval varname(varnum($i))
eval $i
endloop
loop foreach i L2 --quiet
eval varname(i)
eval varname(varnum($i))
eval $i
endloop
</hansl>
As far as I can think, all the evaluations should exhibit the same
results inside each loop. Am I correct?
Actually, no: the expression "varname(i)" always just produces the name of
the variable at position i in the dataset. And in this dataset PAU is at
position 1 and PUS at position 2.
What I guess you have in mind with the first "eval" in these loops
could be done via
eval varname(L1[i])
eval varname(L2[i])
respectively, where the (integer) argument to varname() is not i itself
but the index number of the series at position i in the list.
Allin