# List elements and iterator name collision [duplicate]

Let there be two lists,

exp = {{i, i}, {j, j}};
exp2 = {{r, r}, {o, o}};


and there are two Table commands to access them. Then,

Table[exp[[i, j]], {i, 1, Length[exp]}, {j, 1, Length[exp[[i]]]}]

{{1, 1}, {1, 2}}

Table[exp2[[i, j]], {i, 1, Length[exp2]}, {j, 1, Length[exp2[[i]]]}]

{{r, r}, {o, o}}


So, the variables are being replaced in first case. In case of other languages this problem won't occur but here they are getting iterator value.

If I want to avoid this allocation and take data from set exp what can be done. I tried Holds and Defer but didn't kind of expected result.

• Module[{i, j}, Table... or do not use i,j as iterators. – Kuba Jul 14 '13 at 12:47
• Ya I can always use different names but just in case this situation occurs than how I shall prevent allocation...is it possible ? – Rorschach Jul 14 '13 at 12:58
• Module[{i, j}, Table[exp[[i,j]],{i,2},{j,2}]] like this? – Kuba Jul 14 '13 at 12:59
• If you really insist on using Hold, use it like ReleaseHold@Table[Hold@exp[[#1, #2]] &[i, j], {i, 1, 2}, {j, 1, 2}] or ReleaseHold@ Table[With[{i = i, j = j}, Hold@exp[[i, j]]], {i, 1, 2}, {j, 1, 2}] – panda-34 Jul 14 '13 at 13:36
• Dupolicate of this and this. – Leonid Shifrin Jul 14 '13 at 14:15