View Single Post
08-23-19, 06:14 PM   #13
fusionpit
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 6
That person is saying "for i = 1, #table do" and "for k, v in ipairs(table) do" are basically the same, with the first being slightly more performant. If you had a table that looked like this:
Lua Code:
  1. {
  2.     firstFrame = PlayerFrame,
  3.     secondFrame = FocusFrame,
  4.     thirdFrame = TargetFrame
  5. }
or
Lua Code:
  1. {PlayerFrame, nil, FocusFrame, TargetFrame}
then you would need to use pairs, since ipairs will only iterate over numerical indexes (starting at 1) up to a nil value.

In the case of the second example,
Lua Code:
  1. for k,v in ipairs({PlayerFrame, nil, FocusFrame, TargetFrame}) do
  2.    print(k, v)
  3. end
will output
Code:
1, table:...
while
Lua Code:
  1. for k,v in pairs({PlayerFrame, nil, FocusFrame, TargetFrame}) do
  2.    print(k, v)
  3. end
will output
Code:
1, table:...
3, table:...
4, table:...

Last edited by fusionpit : 08-23-19 at 08:21 PM.
  Reply With Quote