Comparison of programming languages (associative array): Difference between revisions

Content deleted Content added
LPC: copy editing and linking
Lua: copy editing
Line 962:
LPC drivers modern enough to support a foreach() construct use it to iterate through their mapping types.
 
=== [[Lua programming language|Lua]] ===
In [[Lua programming language|Lua]], "table" is a fundamental type that can be used either as an array (numerical index, fast) or as an associative array.
 
The keys and values can be of any type, except nil. The following focuses on non-numerical indexes.
 
Line 984 ⟶ 985:
</syntaxhighlight>
 
If the key is a valid identifier (not a keywordreserved word), the quotes can be omitted. TheyIdentifiers are case sensitive.
 
Lookup is written using either square brackets, which always works, or dot notation, which only works for identifier keys:
Line 993 ⟶ 994:
</syntaxhighlight>
 
You can also loop through all keys and associated values with iterators or for -loops:
 
<syntaxhighlight lang=Lua>