swirl Guide to OmniMark 5   OmniMark home
docs home 
IndexConceptsTasksSyntaxLibrariesOMX VariablesErrors
 
  Related Syntax    
control structure   repeat for    

Syntax

  repeat for name
     (from numeric expression)*
     (to numeric expression)*
     (by numeric expression)*
  actions
  again


Purpose

You can use a repeat for loop to repeat a loop a certain number of times. A repeat for loop has a control variable which has a different value for each iteration of the loop. You can specify the start and end values of the control variable and the steps by which it will be incremented or decremented each time. All these parameters can be omitted, and the appropriate defaults will be applied.

Here is a simple repeat for that repeats 10 times:

  process
     repeat for integer i from 1 to 10
        output "d" % i || " "
     again

Since the default value of the from clause is 1, you can omit the from clause from the program above:

  process
     repeat for integer i to 10
        output "d" % i || " "
     again

You can use the by clause to specify the amount by which the control value is incremented:

  process
     repeat for integer i to 100 by 10
        output "d" % i || " "
     again

The above program prints out:

  1 11 21 31 41 51 61 71 81 91

Notice that the control variable does not always reach the value of the to clause. The loop exits if the next value of the control variable would exceed the value of the to clause.

To make the above program count from 10 to 100, you would need to add a from clause:

  process
     repeat for integer i from 10 to 100 by 10
        output "d" % i || " "
     again

You can change the direction of the loop's progress by specifying a negative value for the by clause.

  process
     repeat for integer i from 100 to 10 by -10
        output "d" % i || " "
     again

You must specify a type for the control variable. This will normally be a numeric type, but it can be any type that meets the following criteria:

While OmniMark does not care how any of the above functions and operators are defined for the type in question, they should behave in a manner analagous to their counterparts in OmniMark or the behavior of a repeat for loop using that type may be unpredictable.

A repeat for loop will exit under any of the following conditions:

OmniMark will throw an #program-errorif the control variable fails to make progress from one iteration to another. Failure to make progress can happen, for instance, if the type of the control variable is float, the value of the control variable is very large, and the value of the by is so small that it does not fall within the significant digits of the control variable value. In this circumstance, incrementing the control variable by the by value does not actually change its value.

If you omit any of the from, to, and by values, the default values will be used. The defaults are:

In all other respects, a repeat for loop behaves like a regular repeat loop.

    Related Syntax
   repeat, again, exit
 
 
----

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

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

Copyright © OmniMark Technologies Corporation, 1988-2000.