Also, someone said that pair execute faster, why?
Forum
![>](img/i_next.png)
![>](img/icons/cs2d.png)
![>](img/i_next.png)
![>](img/i_next.png)
Pairs and ipairs differences?
3 replies![To the start](img/i_first.png)
![Previous](img/i_prev.png)
![Next](img/i_next.png)
![To the start](img/i_last.png)
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.
![To the start](img/i_first.png)
![Previous](img/i_prev.png)
![Next](img/i_next.png)
![To the start](img/i_last.png)