Hi,
I'm struggling with the syntax for a For Each loop across multiple associative arrays.
For example:
q = ["q1"=>11, "q2"=>22, "q3"=>33];
w = ["w1"=>1111, "w2"=>2222, "w3"=>3333];
For single array, just for reference:
For Each( {a, i}, q, Show( i, a ) ); // retrieves indices and keys
For Each( { {a, b}, i }, q, Show( i, a, b ) ); // retrieves indices, keys and values
Analogously, across two arrays it works to some extent:
For Each( {a, i}, Across( q, w ), show( i, a ) );
// retrieves indices and two-item lists of keys of both arrays:
i = 1;
a = {"q1", "w1"};
i = 2;
a = {"q2", "w2"};
i = 3;
a = {"q3", "w3"};
Then drilling further:
For Each( { {a, b}, i }, Across( q, w ), show( i, a, b ) );
// retrieves indices and keys of both arrays separately:
i = 1;
a = "q1";
b = "w1";
i = 2;
a = "q2";
b = "w2";
i = 3;
a = "q3";
b = "w3";
However, I want to get values also. I tried several variants of brace groupings and nothing works. Drawing from the single array syntax this should be the most obvious one:
For Each( { { {a, b}, {c, d} }, i }, Across( q, w ), show( i, a, b, c, d ) );
// returns error:
argument value is invalid in access or evaluation of 'For Each' , Bad Argument( {a, b} ), For Each/*###*/({{{a, b},
{c, d}}, i}, Across( q, w ), Show( i, a, b, c, d ))
I RTFM-ed and RTFF-ed and couldn't find anything.
Of course I can do this:
For Each( { {a, b}, i }, Across( q, w ), show( i, a, b, q[a], w[b] ) );
but this is not the point. It's a matter of elegance.
Any ideas?