CONTINUE (ObjectScript)
Synopsis
CONTINUE:pc
Argument
Argument | Description |
---|---|
pc | Optional — A postconditional expression. |
Description
The CONTINUE command is used within the code block following a FOR, WHILE, or DO WHILE command. CONTINUE causes execution to jump back to the FOR, WHILE, or DO WHILE command. The FOR, WHILE, or DO WHILE command evaluates its test condition, and, based on that evaluation, re-executes the code block loop. Thus, the CONTINUE command has exactly the same effect on execution as reaching the closing curly brace ( } ) of the code block.
CONTINUE takes no arguments (other than the postconditional). At least two blank spaces must separate it from a command following it on the same line.
A CONTINUE can cause execution to jump out of a TRY or CATCH block to return to its control flow statement.
Arguments
pc
An optional postconditional expression that can make the command conditional. InterSystems IRIS executes the CONTINUE command if the postconditional expression is true (evaluates to a nonzero numeric value). InterSystems IRIS does not execute the command if the postconditional expression is false (evaluates to zero). For further details, refer to Command Postconditional Expressions.
Examples
The following example uses a CONTINUE with a postconditional expression. It loops through and prints out all the numbers from 1 to 10, except 3:
Loop
FOR i=1:1:10 {
IF i # 2 {
CONTINUE:i=3
WRITE !,i," is odd" }
ELSE { WRITE !,i," is even" }
}
WRITE !,"done with the loop"
QUIT
The following example shows two nested FOR loops. The CONTINUE jumps back to the FOR in the inner loop:
Loop
FOR i=1:1:3 {
WRITE !,"outer loop: i=",i
FOR j=2:2:10 {
WRITE !,"inner loop: j=",j
IF j '= 8 {CONTINUE }
ELSE { WRITE " crazy eight"}
}
WRITE !,"back to outer loop"
}
QUIT
The following example shows a CONTINUE that exits a TRY block. The CONTINUE jumps back to the FOR statement outside the TRY block.
TryLoop
FOR i=1:1:10 {
WRITE !,"Top of FOR loop"
TRY {
WRITE !,"In TRY block: i=",i
IF i=7 {
WRITE " lucky seven" }
ELSE { CONTINUE }
}
CATCH exp {
WRITE !,"CATCH block exception handler",!
WRITE "Error code=",exp.Code
RETURN
}
WRITE !,"Bottom of the FOR loop"
}
QUIT