Mathematica: Getting part of a list, lithin a loop.

2 replies · 1K views · last reply
teroenza
Messages
190
Reaction score
5
When I use the code directly below, it works (indicated by the "Out:...").
Code:
tmp2 = Flatten[{33, {1, 2 + j, 6}, 55}];(*Out:{33,1,2+j,6,55} *)

tmp2[[4]]; (*Out: 6 *)

But when I use it inside a loop, it acts like the tmp2 list is not the correct size:
Code:
For[j = 0, j <= 5, j++,
tmp2 = Flatten[{33, {1, 2 + j, 6}, 55}]
   Print[tmp2[[4]]]
]

(*Out: Part::partd: Part specification tmp2[[4]] is longer than depth of object. >>*)

This is a minimal example of a larger piece, but I don't see why it's not working.