Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

This question already has an answer here:

The code

Table[i, {i, 5}]

produces the output

{1, 2, 3, 4, 5}

whereas the code

x = {i, 5};
Table[i, x];

produces an error, namely

Table::itform: Argument x at position 2 does not have the correct form for an iterator.

Why, and how do I fix this?

share|improve this question
1  
Try this, Table@@{i,x}. If you check the Attributes of Table you will notice that has the HoldAll attribute so the x will not be evaluated. –  Spawn1701D Apr 22 '13 at 1:56
    
You can also say Table[i,x//Evaluate] but I find it a little ugly :P –  Spawn1701D Apr 22 '13 at 1:57
    
Try With[{x = {i, 5}}, Table[i, x]]. –  chyaong Apr 22 '13 at 9:47
add comment

marked as duplicate by acl, Sjoerd C. de Vries, whuber, Oleksandr R., Artes Apr 22 '13 at 18:07

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer

Table has attribute HoldAll. This means its arguments are left unevaluated:

Attributes[Table]
(* {HoldAll, Protected} *)

Using an Evaluate will force the evaluation order to be as you desire:

x = {i, 5};
Table[i, Evaluate@x]
(* {1, 2, 3, 4, 5} *)
share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.