Difference between FOR and FOR EACH loopsCan somebody explain why this:
dt = Open( "$SAMPLE_DATA/Fitness.jmp" );
col = { :Runtime, :RunPulse, :RstPulse };
y expr = Expr( Y() );
For( c = 1, c <= N Items( col ), c++,
Insert Into( y expr, col[c] );
);
Name Expr(y expr);produces expected output
Y( :Runtime, :RunPulse, :RstPulse )
but this:
dt = Open( "$SAMPLE_DATA/Fitness.jmp" );
col = { :Runtime, :RunPulse, :RstPulse };
y expr = Expr( Y() );
For each({coll, index},col,
Insert Into( y expr, coll );
);
Name Expr(y expr);produces this:
Y( ., ., . )
I would expect it to give the same result? How should I change FOR EACH loop to give the same result?
ScriptingRe: Difference between FOR and FOR EACH loopsMy guess is that the columns get evaluated into current rows values in For Each (you can test this by adding Row() = 1; for example). You might be able to avoid this by using Name Expr()
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Fitness.jmp");
col = {:Runtime, :RunPulse, :RstPulse};
y expr = Expr(Y());
For(c = 1, c <= N Items(col), c++,
Insert Into(y expr, col[c]);
);
Show(Name Expr(y expr));
Row() = 1;
y expr = Expr(Y());
For Each({coll, index}, col,
Insert Into(y expr, coll);
);
Show(Name Expr(y expr));
y expr = Expr(Y());
For Each({coll, index}, col,
Insert Into(y expr, Name Expr(coll));
);
Show(Name Expr(y expr));Re: Difference between FOR and FOR EACH loopsYes, this is it.
It is a strange behavior, since 1. we have For Each Row statement for by row evaluation, and 2. For Each should treat a list (and I'm trying to work with a list of references to columns) same as For loop.
Is this a bug or is it intended behavior?