NetRexx Overview, version 2.05 Copyright (c) IBM Corporation, 2005. All rights reserved. © | 14 Jan 2005
[previous | contents | next]

## Control instructions

NetRexx provides a selection of control instructions, whose form was chosen for readability and similarity to natural languages. The control instructions include if... then... else (as in the ‘greet’ example) for simple conditional processing:

      if ask=’Yes’ then say "You answered Yes"
                   else say "You didn’t answer Yes"

select... when... otherwise... end for selecting from a number of alternatives:

      select
        when a>0 then say ’greater than zero’
        when a<0 then say ’less than zero’
        otherwise say ’zero’
        end

      select case i+1
        when 1 then say ’one’
        when 1+1 then say ’two’
        when 3, 4, 5 then say ’many’
        end

do... end for grouping:

      if a>3 then do
        say ’A is greater than 3; it will be set to zero’
        a=0
        end

and loop... end for repetition:

      /* repeat 10 times; I changes from 1 to 10 */
      loop i=1 to 10
        say i
        end i

The loop instruction can be used to step a variable to some limit, by some increment, for a specified number of iterations, and while or until some condition is satisfied. loop forever is also provided, and loop over can be used to work through a collection of variables.

Loop execution may be modified by leave and iterate instructions that significantly reduce the complexity of many programs.

The select, do, and loop constructs also have the ability to ‘catch’ exceptions that occur in the body of the construct. All three, too, can specify a finally instruction which introduces instructions which are to be executed when control leaves the construct, regardless of how the construct is ended.

[previous | contents | next]

From The NetRexx Language by Mike Cowlishaw, mfc@uk.ibm.com (ISBN 0-13-806332-X, 197pp, Prentice-Hall, 1997).