Marcus Posted December 15, 2011 Share Posted December 15, 2011 So I finally decided to truly learn Lua and I'm a little bit confused. From what I can tell, ipairs() seems to be more useful for iterating over a table setup as an array, for example: arrayVar = {"Gold", "Silver", "Bronze"} And pairs seems to be more useful for iterating over a standard table (keys and value), for example: tableVar = {["Gold"] = 1, ["Silver"] = 2, ["Bronze"] = 3} It appears that pairs also does well with an array style table too, but ipairs does not do well with a key-value table. Am I on the right track or am I misunderstanding this? Quote Link to comment Share on other sites More sharing options...
macklebee Posted December 15, 2011 Share Posted December 15, 2011 The difference between ipairs and pairs Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
Marcus Posted December 15, 2011 Author Share Posted December 15, 2011 Thank you. That was much clearer than the results I got when I googled it. The explanation is also a little bit better than the one in the book, Programming in Lua. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.