swirl Guide to OmniMark 5   OmniMark home
docs home 
IndexConceptsTasksSyntaxLibrariesOMX VariablesErrors
 
     
Looping constructs

OmniMark provides four types of looping constructs, repeat, repeat for, repeat over, and repeat scan.

You can use a repeat loop to perform a series of actions repeatedly. You must explicitly exit a repeat loop using either a throw or an exit:

  process
     local integer foo
     repeat
        output "foo is %d(foo)%n"
        increment foo
        exit when foo = 4
     again

This program will create the following output:

  foo is 0
  foo is 1
  foo is 2
  foo is 3

You can use a repeat for loop to repeat over a block of code a specific number of times. The repeat for loop provides a control variable for the loop and allows you to control the starting and ending values of that variable, as well as the increment it is changed by:

  process
     repeat for integer i from 9 to 27 by 3
        output "d" % i || " "
     again

You can use a repeat over loop to perform the same action on each item on a shelf in turn:

  global stream some-names variable
   initial {"Bob", "Doug", "Andy", "Greg"}

  process
     repeat over some-names
        output some-names || "%n"
     again

You can use a repeat scan to scan a data stream. The repeat scan loop will continue to match data from the source until the source is exhausted or it encounters data that is not matched by any of its alternatives:

  process
     local stream guesses initial {"sufklbp"}
     repeat scan "abcdefghijklmnopqrstuvwxyz"
        match any => the-letter
           do unless guesses matches any** ul the-letter
              output the-letter
           else
              output "*"
           done
     again

       
----

Top [ INDEX ] [ CONCEPTS ] [ TASKS ] [ SYNTAX ] [ LIBRARIES ] [ OMX ] [ OMX ] [ ERRORS ]

Generated: August 11, 2000 at 3:06:23 pm
If you have any comments about this section of the documentation, send email to docerrors@omnimark.com

Copyright © OmniMark Technologies Corporation, 1988-2000.