Essentially, what happens is that inside the for loop you create a table, and the next key is nil, initially. In subsequent cycles, you create the table again, and using the list variable, you assign it next key, which is now a link to the previous table, and so on.
I will give you an example.
list = nil -- this is optional for i=1,3 do list = {val=i, next=list} end print(list.val)
If you were to print(list.val) or print(list.next.val) they would print different values. I know it kind of baffled me when I first saw it.
source share