swirl
Guide to OmniMark 9   OmniMark home
docs home 
IndexConceptsTasksSyntaxLibrariesLegacy LibrariesErrors
 
     

Looping constructs

OmniMark provides five types of looping constructs: repeat, repeat for, repeat to, 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 to to repeat a block of code a specific number of times. The loop will repeat the number of times specified by an integer expression following the to:

  process
     repeat to 5
        output "X"
     again

You can use a repeat for loop to repeat over a block of code a specific number of times. The 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 ] [ LEGACY LIBRARIES ] [ ERRORS ]

OmniMark 9.1.0 Documentation Generated: September 2, 2010 at 1:35:14 pm
If you have any comments about this section of the documentation, please use this form.

Copyright © Stilo International plc, 1988-2010.