Skip to main content

Software > Software Development > IBM REXX Family >

NetRexx

Technical detail

Do instruction

do [label name] [protect term]; instructionlist

  [catch [vare =] exception;

    instructionlist]...

  [finally[;]

    instructionlist]

  end [name];

where name is a non-numeric symbol
and instructionlist is zero or more instructions

The do instruction is used to group instructions together for execution; these are executed once. The group may optionally be given a label, and may protect an object while the instructions in the group are executed; exceptional conditions can be handled with catch and finally.

The most common use of do is simply for treating a number of instructions as group.

Example:

  /* The two instructions between DO and END will both */
/* be executed if A has the value 3. */
if a=3 then do
a=a+2
say 'Smile!'
end

Here, only the first instructionlist is used. This forms the body of the group.

The instructions in the instructionlists may be any assignment, method call, or keyword instruction, including any of the more complex constructions such as loop, if, select, and the do instruction itself.

Label phrase

If label is used to specify a name for the group, then a leave which specifies that name may be used to leave the group, and the end that ends the group may optionally specify the name of the group for additional checking.

Example:

  do label sticky
x=ask
if x='quit' then leave sticky
say 'x was' x
end sticky

Protect phrase

If protect is given it must be followed by a term that evaluates to a value that is not just a type and is not of a primitive type; while the do construct is being executed, the value (object) is protected -- that is, all the instructions in the do construct have exclusive access to the object.

Both label and protect may be specified, in any order, if required.

Exceptions in do groups

Exceptions that are raised by the instructions within a do group may be caught using one or more catch clauses that name the exception that they will catch. When an exception is caught, the exception object that holds the details of the exception may optionally be assigned to a variable, vare.

Similarly, a finally clause may be used to introduce instructions that will always be executed at the end of the group, even if an exception is raised (whether caught or not).

The Exceptions section has details and examples of catch and finally.

 

 

PreviousTable of contents Next
We're here to help
Easy ways to get the answers you need.
E-mail us

or call us at
877-426-3774
Priority code:
104CBW67