Garry's Mod Wiki

Revision Difference

Global.pairs#527838

<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>⤶ <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> <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>⤶ <description>Iterates through all players on the server and prints their names.⤶ **Note: In sequential tables like <page>player.GetAll</page> or <page>ents.GetAll</page>, it's more efficient to use <page>Global.ipairs</page> instead of `pairs`.**⤶ ⤶ </description>⤶ <code> for k, v in pairs( player.GetAll() ) do print( v:Nick() ) end </code> <output>A list of players in console.</output> ⤶ </example></example>