The statement FOREACH KEY enumerates all keys in a MAP and runs the model part for every key.
Definition:
FOREACH KEY key IN map
DO
ITP-model part
OD
FOREACH KEY key IN SORTED map
DO
ITP-model part
OD
The enumeration variable (key) of type TEXT must be declared before the FOREACH loop. The map (map) can be any type of MAP. You can use the keyword SORTED to enumerate the keys in a alphabetically-lexicographically sorted order. If this keyword is omitted, the ordering of the enumeration is undefined. Changes to the map within the DO … OD section do not affect the enumeration.
Example:
# BEGIN
MAP NUMBER example
ASSIGN example["one"] := 1
ASSIGN example["two"] := 2
ASSIGN example["three"] := 3
ASSIGN example["four"] := 4
TEXT key
FOREACH KEY key IN SORTED example
DO
#
@(key) @(number(example[key];0))
#
ASSIGN example["magic"] := 42
OD
#
Show changes: Element 'magic' = @(number(example["magic"];0))
#
END #
Result:
four 4
one 1
three 3
two 2
Show changes: Element 'magic' = 42
Note
Note that the 'magic' element is not enumerated, even tough it is added within the DO … OD part.