Skip to content

Table

Table[expr, n] returns a list with n copies of expr.

Table[expr, {sym, n}] returns a list with expr evaluated with sym = 1 to n.

Table[expr, {sym, m, n}] returns a list with expr evaluated with sym = m to n.

Attributes[Table] := {HoldAll, Protected}

Simple examples

In[1]:= Table[a, 5]
Out[1]= {a, a, a, a, a}
In[2]:= Table[i, {i, 5, 10}]
Out[2]= {5, 6, 7, 8, 9, 10}
Create a list of the first 10 squares:
In[3]:= Table[n^2, {n, 1, 10}]
Out[3]= {1, 4, 9, 16, 25, 36, 49, 64, 81, 100}
Iteration definitions do not have side effects:
In[4]:= i
Out[4]= i
In[5]:= listTableTestState`i = 22
Out[5]= 22
In[6]:= Table[i, {i, 5, 10}]
Out[6]= {5, 6, 7, 8, 9, 10}
In[7]:= i
Out[7]= 22

Further examples

In[1]:= Table[x[99], {x[_], 0, 2}]
Out[1]= {0, 1, 2}