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}]
  • 3
    $\begingroup$ 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. $\endgroup$
    – C. E.
    Commented Aug 24, 2014 at 18:34

1 Answer 1


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]]




  • $\begingroup$ 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}] $\endgroup$ Commented Aug 24, 2014 at 18:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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