Regarding the problem of adding data to table with table.insert
z_san
z_san 2018-06-13 18:13:12
0
4
1499

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}

z_san
z_san

reply all (3)
z_san

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)

      • reply --print(i) is a comment
        z_san author 2018-06-15 17:04:56
      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!