This is documentation for Mathematica 3, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)
 Documentation / Mathematica / Built-in Functions / Programming / Assignments  /
AppendTo

  • AppendTo[ s , elem ] appends elem to the value of s, and resets s to the result.
  • AppendTo[ s , elem ] is equivalent to s = Append[ s , elem ].
  • AppendTo[ s , elem ] does not evaluate s.
  • You can use AppendTo repeatedly to build up a list.
  • An alternative and often more efficient way to build up a list is to use a sequence of assignments of the form s = s , elem , and then to call Flatten on the resulting structure.
  • See the Mathematica book: Section 2.4.4.
  • See also: PrependTo.

    Further Examples

    This defines a list.

    In[1]:=

    Out[1]=

    This appends the number to the end of the list.

    In[2]:=

    Out[2]=

    The original list is changed as a side effect.

    In[3]:=

    Out[3]=

    On the other hand, Append does not change the new version of the list.

    In[4]:=

    Out[4]=

    In[5]:=

    Out[5]=

    In[6]:=