OmniMark provides four types of looping constructs: repeat, repeat for, repeat over, and repeat scan.
A repeat loop will repeat the execution of the actions it contains until an explicit exit action is encountered in the loop.
process local integer foo repeat output "foo is " || "d" % foo || "%n" increment foo exit when foo = 4 again |
A repeat for loop repeats for each of the values of a control variable.
Process local integer foo repeat for integer foo from 1 to 7 by 2 output "foo is " || "d" % foo || "%n" again |
A repeat over loop repeats for each item on a shelf:
process local stream duckType variable set new duckType key "Sarkidiornis melanotos" to "Comb Duck" set new duckType key "Anas crecca" to "Green-winged Teal" set new duckType key "Melanitta perspicillata" to "Surf Scoter" repeat over duckType output key of duckType || "=" || duckType || "%n" again |
Within a repeat over loop, you refer to the current item on the shelf by the name of the shelf alone, without an indexer.
You can use a repeat scan loop to scan data the same way you use submit and a set of find rules. The only differences are that a repeat scan is local to a single rule or function, and data not matched by a repeat scan does not stream through to current output. Instead, a repeat scan exits if it encounters any data it cannot match:
process local integer word-count repeat scan "Mary had a little lamb" match letter+ increment word-count match any again output "d" % word-count |