Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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.

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
I would like to petition that this question be un- marked as duplicate. This question is REALLY about how you pass an entire iterator form as a value to a function. The other question is about getting a built in function to correctly handle a new, user-specified iterator form. They are just superficially similar in that they both (incidentally) use the iterator argument to Table as an example problem for the actual underlying question. – billc Aug 20 '15 at 5:13
up vote 5 down vote accepted

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

(* {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

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