Syntax:
LOOP LOOP FOREVER LOOP FOR count LOOP i=1 TO 10 BY 3 FOR n LOOP j=1 TO 100 WHILE k<7 LOOP index OVER collection
LOOP ... END is the NetRexx repetition construct. LOOP follows the rules of Rexx and Object Rexx repetitive DO, except that the control variable must be a simple name (not an array reference or other term) that does not conflict with a label or control variable at an outer level. A control variable must also always be a variable or property in the current class.
WHILE and UNTIL are allowed as in Rexx. 'LOOP' on its own means 'LOOP FOREVER'. 'LOOP FOR count' replaces 'DO count'. CATCH and FINALLY can be used (see "Exceptions" section for details).
The FOR keyword accepts any count that can be converted to an integer (int). Negative FOR counts are treated as zero.
LOOP OVER is used to work through the values in a collection of Rexx indexed variables or a Java Dictionary (such as a Hashtable). The LOOP instruction takes a snapshot of the indexes into the collection, and then for each iteration of the loop the control variable ('index', in the example above) is set to the next available index.
For example:
mycoll='' mycoll['Tom']=1 mycoll['Dick']=2 mycoll['Harry']=3 loop name over mycoll say mycoll[name] end
might display:
3 1 2
Note that the order in which the values are returned are undefined; all that is known is that all indexes available at the start of the loop will be available and assigned to 'name' in turn as the loop iterates.
The name of a loop (which may be used on END, LEAVE, and ITERATE for the loop) is the name of the control variable (if any). Alternatively, an explicit name may be specified using the LABEL keyword; this overrides any name derived from the control variable name (that is, the variable name cannot be used to refer to the loop if a label is specified). For example:
loop label pooks i=1 to 10 loop label hill while j<3 ... if a=b then leave pooks ... end hill end pooks
In this example, the LEAVE instruction leaves both loops.
As with DO and SELECT, the PROTECT keyword may be used at the start of a LOOP instruction. If used, PROTECT is followed by a term that must resolve to an object reference; while the loop is being executed, the object is protected -- that is, the code in the loop has exclusive access to the object. For example:
loop protect myobject while a<b ... end
Both PROTECT and LABEL may be specified, if needed.
[ previous section | contents | next section ]
From 'netrexx.doc', version 1.00.
Copyright(c) IBM Corporation, 1996, 1997. All rights reserved. ©