Next: ’for-as-package’, Previous: ’for-as-across’, Up: Iteration Control [Contents][Index]
This is the sixth of seven for/as syntaxes.
for var [type-spec] being {each | the} {hash-key | hash-keys | hash-value | hash-values} {in | of} hash-table [using ({hash-value | hash-key} other-var)] as var [type-spec] being {each | the} {hash-key | hash-keys | hash-value | hash-values} {in | of} hash-table [using ({hash-value | hash-key} other-var)]
This construct iterates over the elements, keys, and values of a hash table. Iteration stops when there are no more hash keys or hash values to be referenced in the specified hash table.
var
takes on the value of each hash key or hash value in the
specified hash table.
marks the loop method to be used, either ‘hash-key’ or ‘hash-value’.
For purposes of readability, the loop keyword ‘each’ should follow the loop keyword ‘being’ when ‘hash-key’ or ‘hash-value’ is used.
The loop keyword ‘the’ is used with ‘hash-keys’ and ‘hash-values’.
These loop keywords access each key entry of the hash table. If the name ‘hash-value’ is specified in a ‘using’ construct with one of these loop methods, the iteration can optionally access the keyed value. The order in which the keys are accessed is undefined; empty slots in the hash table are ignored.
These loop keywords access each value entry of a hash table. If the name ‘hash-key’ is specified in a using construct with one of these loop methods, the iteration can optionally access the key that corresponds to the value. The order in which the keys are accessed is undefined; empty slots in the hash table are ignored.
The loop keyword ‘using’ marks the optional key or the keyed value to be accessed. It allows you to access the hash key if iterating over the hash values, and the hash value if iterating over the hash keys.
These loop prepositions mark the hash table hash-table
.
Next: ’for-as-package’, Previous: ’for-as-across’, Up: Iteration Control [Contents][Index]