b = {}
for i=, do
b[i] = i
end -- method one
for i, v in pairs(b) do
print (i, v)
end -- method two
for i, v in ipairs(b) do
print (i, v)
end -- method three
for i = , #b do
print (i, b[i])
end -- method four
for i = , table.maxn(b) do
print (i, b[i])
end
lua常用的四种遍历,前两种是泛型遍历,后两种是数值的遍历.