Almost any statement in OmniMark can be made conditional simply by adding a when or unless keyword followed by a test. For example, any rule can have conditions added to it. The following rule will fire only when the value of count1 equals 4:
find "duck" when count1 = 4 output "I found a duck%n" |
The basic conditional construct is the do when...done block.
do when foo = 4 output "Yes, the value of foo is four%n" done |
You can add an else option:
do when output-in-upper-case = true output "ug" % words || "%n" else output words || "%n" done |
You can handle multiple cases using else when:
do when foo = 4 output "Yes, the value of foo is four%n" else when count1 = 5 output "The value of foo is five%n" else when count1 = 6 output "The value of foo is six%n" else output "The value of foo is not 4, 5, or 6%n" done |
You can construct complex conditional statements using & (and) and | (or):
do when (foo > 12 | foo < 56) & bar > 3 |
Another form of conditional construct is the do select construct:
do select foo case 1 to 5 output "foo is small%n" case 50 to 100 output "foo is large%n" else output "foo is medium sized%n" done |
You can also implement conditional logic by using the do scan construct, which uses scanning to evaluate data. Thus you can build your conditions based on pattern matching:
process do scan telephone-number match "(" digit{3} ")" digit{3} "-" digit{4} output "long distance call%n" match digit{3} "-" digit{4} output "local call%n" else output "unknown format%n" done |