Jump to content

Question about 'in ipairs'..


Recommended Posts

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...