Jump to content

Lua question: pairs() vs ipairs()


Marcus
 Share

Recommended Posts

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?

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...