Also, someone said that pair execute faster, why?
Forum
CS2D Scripts Pairs and ipairs differences?Pairs and ipairs differences?
3 replies 1
Also, someone said that pair execute faster, why?
1
2
3
4
2
3
4
local t = {1,2} t[3] = 3 t[7] = 7 t["test"] = "hello world"
1
2
3
2
3
for k,v in pairs(t) do 	print("t["..k.."] = "..v) end
t[1] = 1
t[2] = 2
t[3] = 3
t[7] = 7
t[test] = hello world
1
2
3
2
3
for k,v in ipairs(t) do 	print("t["..k.."] = "..v) end
t[1] = 1
t[2] = 2
t[3] = 3
They are both quite fast, with pairs being slightly faster than ipairs (if the ammount of keys iterated are the same, of course)
Anyways, a for loop is always faster.
If you are using a table that has a string index then you must use pairs, otherwise ipairs is the way to go.
1