2 added 356 characters in body edited Jul 29 '18 at 9:53 m0nhawk 3,00211 gold badge1616 silver badges3333 bronze badges YouThe loop is infinite, because the result of Append is the new list, not the modification of existing. Documentation: Append[expr,elem] gives expr with elem appended.  And: AppendTo[s,elem] appends elem to the value of s, and resets s to the result.  So, you either need to reassign the value of Append or use AppendTo: list={1}; n=2; While[Last@list<10,list=Append[list,n];n++]  Or: list={1}; n=2; While[Last@list<10,AppendTo[list,n];n++]  Both will yield the same result. You either need to reassign the value of Append or use AppendTo: list={1}; n=2; While[Last@list<10,list=Append[list,n];n++]  Or: list={1}; n=2; While[Last@list<10,AppendTo[list,n];n++]  Both will yield the same result. The loop is infinite, because the result of Append is the new list, not the modification of existing. Documentation: Append[expr,elem] gives expr with elem appended.  And: AppendTo[s,elem] appends elem to the value of s, and resets s to the result.  So, you either need to reassign the value of Append or use AppendTo: list={1}; n=2; While[Last@list<10,list=Append[list,n];n++]  Or: list={1}; n=2; While[Last@list<10,AppendTo[list,n];n++]  Both will yield the same result. 1 answered Jul 29 '18 at 8:38 m0nhawk 3,00211 gold badge1616 silver badges3333 bronze badges You either need to reassign the value of Append or use AppendTo: list={1}; n=2; While[Last@list<10,list=Append[list,n];n++]  Or: list={1}; n=2; While[Last@list<10,AppendTo[list,n];n++]  Both will yield the same result.