There are two looping constructs and a conditional construct. The basic looping
construct has the form while ... do ... wend
. While the expression to the
left of the do
keyword is true do the expression to the right of the
do
keyword. The expression on the left must produce a boolean value.
The left and right expressions can include any complex expression,
such as nested looping and conditional constructs or function calls.
An example of this looping construct is given below with the definition of
strlen
(to return the length of a string).
%%EQUATE strlen(s) 0 >> x while s'x <> 0 do x + 1 >> x wend outputs(x)
The other looping construct has the form roll ... through
. The
expression between the keywords is executed once for every record in the
master database (filter conditions still apply). For example here is the
definition of a function to return the number of records in the database.
%%EQUATE nrecs 0 >> n roll n + 1 >> n through outputs(n)
The looping syntax can optionally include a colon suffix form. This allows
looping through a named database (no filter conditions apply when this is
the master database).
This form is roll ... through:database
where database
is the
name of a valid loaded database (without the pathname or extension). Fields
from other databases cannot be accessed within the loop unless the ->
syntax is used, so if looping through a database other than the master database
then this form must be used within the loop to access fields of the master
database. Note that this applies even to nested equate calls within the loop
body for example.
The conditional construct has one of the forms if ... then ... endif
and if ... then ... else ... endif
. If the boolean expression bewteen
the if
and then
keywords is true execute the expression between
the then
and else
or endif
keywords otherwise execute the
expression between the else
and the endif
keywords if it exists.
Each expression can be as complex as required (including nested conditional
and looping constructs, and function calls) but need not have any contents.
Below are two examples of the conditional construct.
%%EQUATE test inputs(a,c) if a > 0 and a < 12 then "hello" >> b endif if not (c = 5) then 5 >> c "no" >> b else if not (c = 3) then 3 >> c "world" >> b endif endif outputs(b,c)
Note that the endif
keyword must always be present. The elif
keyword can be used for multiple conditions grouped up under one endif
keyword (this saves having to nest conditions). The example above is shown
below using the elif
keyword to simplify the statements.
%%EQUATE test inputs(a,c) if a > 0 and a < 12 then "hello" >> b endif if not (c = 5) then 5 >> c "no" >> b elif not (c = 3) then 3 >> c "world" >> b endif outputs(b,c)
There is a known bug preventing the use of a roll .. through
construct
within a condition construct when the colon suffix form is used.
Go to the first, previous, next, last section, table of contents.