This is documentation for Mathematica 8, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)

AppendTo

AppendTo
appends elem to the value of s, and resets s to the result.
  • You can use AppendTo repeatedly to build up a list, though Sow and Reap will usually be more efficient. »
Assign to a list:
Include a new value at the end of the list:
The value assigned to has changed:
Assign to a list:
In[1]:=
Click for copyable input
Out[1]=
Include a new value at the end of the list:
In[2]:=
Click for copyable input
Out[2]=
The value assigned to has changed:
In[3]:=
Click for copyable input
Out[3]=
Use a head other than List:
This assigns to a sparse matrix:
Add a row to the matrix:
Appending an element with inconsistent dimensions requires converting to ordinary lists:
Assign to be a 2×2 matrix:
Append a row to :
Append a column to :
is now a 3×3 matrix:
The first argument must be a variable:
The first argument must be a variable with a value:
The first argument must be assigned to something which can be appended to:
Something for which AtomQ is True cannot be appended to:
Using AppendTo to accumulate values in large loops can be slow:
There are many alternatives, such as using Reap and Sow:
New in 1 | Last modified in 5