2

The following simple code of course works:

Table[n^2, {n, 3, 15, 2}]
(* Out: {9, 25, 49, 81, 121, 169, 225} *)

I would then like to construct the iterator programmatically. However, the following approach does not work:

d = {n, 3, 15}      (* Out: {n, 3, 15} *)
a = Append[d, 2]    (* Out: {n, 3, 15, 2} *)
Table[n^2, a]

Error: Non-list iterator a at position 2 does not evaluate to a real numeric value.

How can I avoid that error?

MarcoB
  • 67,153
  • 18
  • 91
  • 189
cybervigilante
  • 599
  • 2
  • 7
  • 5
    You need to use Evaluate, for variable iterator lists. d = {n, 3, 15}; a = Append[d, 2]; Table[n^2, Evaluate[a]] – flinty Jan 27 '22 at 11:02

0 Answers0