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

I would like to make a Table whose iterator has a dynamically updated endpoint, i.e.


Is this possible? Here is the context:

SetterBar[Dynamic@n, Range[1, 10, 1]]
         For[ i=3,i<=Dynamic[n]+4,i++,

I get the error

Iterator {i,1,4+1} does not have appropriate bounds.

As another example of how I'd like to use this, here is fully functional code:

Manipulate[Table[ToExpression["x" <> ToString@i], {i, 1,Dynamic@n + 1}],
           {x1, 1, 10}, {x2, 1, 10}]
share|improve this question
You need to think about where you place Dynamic. In this simple example you should place it outside of Table. If you wrap Table in something else, Dynamic might have to be moved even further away from Table. The idea is to make the expression dynamic, not just one variable. Without knowing what you are planning on using this for any answers that we can provide might not help you that much. – C. E. Aug 24 '14 at 18:34
up vote 3 down vote accepted

As mentioned in the comment by Pickett, you have to wrap Dynamic around the expression that is to be displayed. You also forgot to return a value from your function f. Here is a modification of your code that works:


f[x_] := Module[{y},
  y = Table[0, {i, 1, n + 4}]; 
  For[i = 3, i <= n + 4, i++, y[[i]] = y[[i - 1]] + 2 y[[i - 2]]];

n = 1;
SetterBar[Dynamic@n, Range[1, 10, 1]]




share|improve this answer
Thanks so much! I guess I was writing the Dynamics inside-out, or so to say - I also fixed the extra line I added to the question, thanks to you: Manipulate[ Dynamic[Table[ ToExpression["x" <> ToString@i], {i, 1,n + 1}]], {x1, 1, 10}, {x2, 1, 10}] – David Roberts Aug 24 '14 at 18:55

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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