Understanding pairs

The pairs iterator function is provided by Lua; it is used to iterate over a table. The pairs function returns two variables—let's call them k and v. The k variable will contain the key being iterated over and the v variable will contain the value. v can be nil, but k cannot. The following code demonstrates using pairs to iterate over a simple table:

vector = { x = 34, y = 22, z = 56 }

for k, v in pairs(vector) do
print ("key: " .. k .. ", value: " .. v)
end
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.128.205.21