I don’t know what topic to put this under, was wondering whats the difference between these two, if any:
local ThisTable = {key = "value"}
for key, value in pairs(ThisTable) do
print(key, value)
end
local i, value, key = pairs(ThisTable)
while true do
local key, value = i(value, key)
if key then
else
break
end
key = value
print(key, value)
end
pairs returns the next iterator, the table, and the starting position for the iteration. There’s literally no difference except one will go until it errors. You may as well just do this:
for k, v in next, tbl, ThisTable, nil do
print(key, value)
end
The first example is concise and does not introduce unnecessary assignments.
Both do the same thing. The latter can/may lead to misleading results as key may not match the actual key from the table but will instead hold the value.