Garry's Mod Wiki

Revision Difference

Global.pairs#511312

<function name="pairs" parent="Global" type="libraryfunc">⤶ <description>⤶ Returns an iterator function(<page>Global.next</page>) for a for loop that will return the values of the specified table in an arbitrary order.⤶ ⤶ For alphabetical **key** order use <page>Global.SortedPairs</page>.⤶ ⤶ ⤶ For alphabetical **value** order use <page>Global.SortedPairsByValue</page>.⤶ </description>⤶ <realm>Shared and Menu</realm>⤶ <args>⤶ <arg name="tab" type="table">The table to iterate over</arg>⤶ </args>⤶ <rets>⤶ <ret name="" type="function">The iterator (<page>Global.next</page>)</ret>⤶ <ret name="" type="table">The table being iterated over</ret>⤶ <ret name="" type="any">**nil** (for the constructor)</ret>⤶ </rets>⤶ </function>⤶ ⤶ <example>⤶ <description>Iterates through all players on the server and prints their names.</description>⤶ <code>⤶ for k, v in pairs( player.GetAll() ) do⤶ print( v:Nick() )⤶ end⤶ </code>⤶ <output>A list of players in console.</output>⤶ ⤶ </example>