OSF DCE Administration Guide--Core Components

OSF DCE Administration Guide—Core Components
2.9.2.3 The for Loop
The for loop also behaves just like its C counterpart. Although for is more complex than
its sibling while, for keeps all of the loop control information together, making it easier
to see what’s going on. The for command syntax is
for initial_expression test reinit script_body
To use for, set an initial expression and then test for that condition before executing the
script body. After executing the script body, the for command reinitializes the initial
expression and again tests for the new value, repeating the loop until the test becomes
false.
The following example shows a for loop that performs an operation a specified number
of times and stops. In this example, we create 50 guest principal names in the registry.
dcecp> for {set i 0} {$i < 50} {incr i} {
> principal create guest$i
> }
dcecp>
2.9.3 Terminating Loops with continue and break
The continue and break commands terminate loops started with the while, for, and
foreach commands.
Use the continue command to terminate the current iteration of a loop. For instance,
your loop can test for, and selectively ignore, particular elements in a list while
continuing to operate on the rest of the elements. Use the break command to
immediately terminate loop execution.
The following example script fragment is a foreach command loop that includes
continue and break commands. The foreach command looks through all the DTS
servers in a cell until it finds one that is a time-provider. (A time-provider is a special
DTS server that receives time from an external time source.) If the first server in the list
(created by the dts catalog operation) returns output from a dts show operation, the
continue command invokes the next lines in the script which search the output for the
{provider yes} attribute and value. If the provider attribute (examined by the attrlist
getval operation) is yes, the script sets the server variable to be the name of that DTS
server, and the break command terminates the entire foreach loop.
2 20 Tandem Computers Incorporated 124243