Hi, misterfriendly.
Paeon’s mistake was that he was setting numbersList to {“1”} inside the repeat instead of before it, so he was getting a new {“1”} with each iteration instead of continuing with the list to which he’d just added an item.
Your suggestion uses concatenation to grow the list. This can be useful sometimes, but isn’t as efficient as setting the end of the list to the required value.
set end of numbersList to stNumber
--> Appends stNumber to numbersList.
--> Result: the same physical list, but with an additional item.
set numbersList to numbersList & stNumber
--> stNumber is coerced to list too (if it isn't one already, which it isn't here)
--> and the result is concatenated to numbersList.
--> Result: a third list containing the same items as the other two
--> and whose length is the sum of the lengths of the other two.
--> The variable 'numbersList' is reassigned to this new list.
It should be obvious from this that the process of “growing a list” by concatenation involves the creation and discarding of progressively longer lists, which can begin to affect performance. (Technically, this also happens a little with the other method, but only when adding an item exceeds the list’s current memory allocation.)
Here are some ramifications of concatenating to a list:
{1, 2, 3, 4, 5} & 6 -- Integer coerced to list {6} before concatenation.
--> {1, 2, 3, 4, 5, 6}
{1, 2, 3, 4, 5} & {6} -- Integer already in a list.
--> {1, 2, 3, 4, 5, 6}
{1, 2, 3, 4, 5} & {6, 7, 8} -- Multi-item list.
--> {1, 2, 3, 4, 5, 6, 7, 8}
{1, 2, 3, 4, 5} & {{6, 7, 8}} -- Multi-item list in a list.
--> {1, 2, 3, 4, 5, {6, 7, 8}}
{1, 2, 3, 4, 5} & {a:9, b:10} -- Record coerced to list {9, 10} before concatentation.
--> {1, 2, 3, 4, 5, 9, 10}
{1, 2, 3, 4, 5} & {{a:9, b:10}} -- Record in a list.
--> {1, 2, 3, 4, 5, {a:9, b:10}}
Hope this is interesting. 