方法一,可以用for来遍历:
do
table_week={
“w”,
“e”,
“r”,
“t”,
“y”,
“u”,
“i”,
}
for i=1, #table_week do
print(table_week[i])
end
end
#后面接一个数组或者tabe来遍历它,i是该table或者数组的起始下标。
方法2:
do
table_week={
“w”,
“e”,
“r”,
“t”,
“y”,
“u”,
“i”,
}
for i, v in pairs(table_week) do
print(i)
end
end
这种是采用迭代器的方式遍历的,i为下标,v为table或者数组的值。
方式3:
do
table_week={
“w”,
“e”,
“r”,
“t”,
“y”,
“u”,
“i”,
}
for i in pairs(table_week) do
print(i);
end
end
i为table或者数组的下标。
方式4:
do
table_view={
“w”,
“e”,
“r”,
color1=”red”,
color2=”blue”,
,
,
,
}
for i, v in pairs(table_view) do
if type(v)==”table” then
for new_table_index, new_table_value in pairs(v) do
print(new_table_value)
end
else
print(v)
end
end
end
注:type(v)
功能:返回参数的类型名(“nil”,”number”, “string”, “boolean”, “table”, “function”, “thread”, “userdata”)