G.pairs
From GMod Wiki
Revision as of 01:56, 8 February 2011 by [ĜĞ] arsenicCatnip  (Talk | contribs)
				
			| Function | |
| Syntax | 
		pairs( Table  table ) Where is this used?  | 
	
| Description: | |
| Returns an iterator function for a for loop that will return the values of the specified table in an arbitrary order. | |
| Returns: | Function , Table | 
| Part of Library: | Global Functions | 
| Realm: | 
		 | 
	
| BBCode Link: | [b][url=http://wiki.garrysmod.com/?title=G.pairs]G.pairs [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] | 
	
Example
| Description | Prints the name of all players. | 
|---|---|
| Used on | |
| Code | for k,v in pairs( player.GetAll() ) do print( v:Name() ) end  | 
| Output | Names of players. | 
Additional Notes
- pairs is faster than ipairs[1][2] - but returns values in an arbitrary order. Use ipairs if order is important , pairs otherwise.
 - for k,v in pairs(tab) do is equivalent to for k,v in next, tab do, but is neater.