NetRexx Overview, version 1.148
Copyright (c) IBM Corporation, 1998. All rights reserved. ©
23 Dec 1998
[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
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
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.


[previous | contents | next]

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