Feche1320 Posted May 3, 2011 Share Posted May 3, 2011 What does 'in ipairs' or 'in pairs' do on a loop and what other use it could have? Thanks Link to comment
proracer Posted May 3, 2011 Share Posted May 3, 2011 You can read about it here: http://lua-users.org/wiki/ForTutorial OR http://www.lua.org/pil/4.3.4.html and http://www.lua.org/pil/4.3.5.html Good luck. Link to comment
Wojak Posted May 3, 2011 Share Posted May 3, 2011 ipirs() is an iterator function that only work for tables indexed by numbers starting from 1, it also sort the indexes while looping thru them, but it will not work if a index skip a number, for exemple: local table = { [2]="b", [3]="b",[1] = "a" } "for" will loop thru all 3 cells local table = { ,[2]="b", [4]="b",[1] = "a" } "for" will stop on 2 cell if you want to loop tabels indexed by eny data type (including elements) you should use "pairs()" in expresion for key, var in (i)pairs(sometable) do key will contain the index var will contain the value of the cell Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now