lua
iterating tables
looping over a tables values with pairs, ipairs, or a plain numeric for
use pairs n throw the key away with _
for _, v in pairs(t) do
print(v)
endwhich loop
- array style table (
{ a, b, c }), useipairsinstead, it goes in order from 1 n stops at the firstnil pairshas no guaranteed order, it gives you everything, hash part included, but in whatever order the table happens to store it- a plain numeric loop is the fastest option for arrays
for i = 1, #t do
local v = t[i]
print(v)
end