next

From Garry's Mod
Revision as of 07:35, 19 April 2017 by Code gs (Talk | contribs)
Jump to: navigation, search
 next( )

Contents

Description

Returns the next key and value pair in a table.

NOTE

Non-numerical keys in Lua have no specific order, and will be returned in whatever order they exist in memory. This may not always be in ascending order or alphabetical order.

Arguments

table tab

The table

Arguments

any prevKey=nil

The previous key in the table.

Returns

any

The next key for the table. If the previous key was nil, this will be the first key in the table. If the previous key was the last key in the table, this will be nil.

Returns

any

The value associated with that key. If the previous key was the last key in the table, this will be nil.

Examples

Example

Returns whether the table is empty or not

local function IsEmptyTable( t )
	return next( t ) == nil
end

local mytable = {}
print( "mytable is empty:", IsEmptyTable( mytable ) )
mytable["hello"]=true
print( "mytable is empty:", IsEmptyTable( mytable ) )

Output:

mytable is empty: true
mytable is empty: false
Personal tools
Navigation