在lua文件中,遍历五个表,将五个表的数据放在表中,并且表中的一组数据又五个表中的每一个数据组成的
时间: 2024-03-09 18:51:45 浏览: 13
好的,那么在 Lua 中,您可以通过以下代码来实现您的需求:
```lua
-- 假设您有五个表,分别为 table1, table2, table3, table4, table5
local tableList = {table1, table2, table3, table4, table5} -- 将五个表存入一个列表中
local resultTable = {} -- 用于存储遍历后的结果
-- 遍历五个表并将数据存入 resultTable 中
for i = 1, #tableList do
local currentTable = tableList[i]
for j = 1, #currentTable do
local subResultTable = {} -- 存储一组数据的结果表
for k = 1, #tableList do
table.insert(subResultTable, tableList[k][j]) -- 将五个表中的对应数据插入 subResultTable 中
end
table.insert(resultTable, subResultTable) -- 将 subResultTable 插入 resultTable 中
end
end
-- 输出遍历后的结果
for i = 1, #resultTable do
local subResultTable = resultTable[i]
for j = 1, #subResultTable do
io.write(subResultTable[j], " ")
end
io.write("\n")
end
```
以上代码会将五个表中的数据遍历一遍,并将每组数据存入一个新的表中。每组数据又由五个表中的对应数据组成。最后,遍历新表并输出结果。