Regarding the problem of adding data to table with table.insert
z_san2018-06-13 18:13:12
0
4
1576
arr={}
for i=1,100 do
-- print(i)
table.insert( arr , 1, i )
end
In the above code, when table.insert in Lua adds data to the table, why does the array structure become {100,99,98,.. ....,3,2,1} instead of {1,2,3,4....99,100}
Solved. When table.insert adds data to the table, it inserts the first position every time. That is, the table structure for the first cycle is {1}, and the structure for the second cycle is {2,1}. Three times {3,2,1}..., and so on
Solved. When table.insert adds data to the table, it inserts the first position every time. That is, the table structure for the first cycle is {1}, and the structure for the second cycle is {2,1}. Three times {3,2,1}..., and so on
Because the data will not be returned until the loop is completed.
Try replacing --print(i) with ++print(i)