Terminating an if construct

breakif

Terminate an if construct


SYNTAX

breakif

The breakif command causes execution to jump out of a block of statements controlled by an ifthenelse condition. It may only be used within the braces of an if or else construct.

Control is passed to the statement following the terminating right brace of the if construct. If there is no else clause, this is the statement following the terminating right brace of the if clause. If there is an else clause, it is the statement following the terminating right brace of the else clause. If the else clause consists of a single statement without enclosing braces, then control passes to the statement following this single statement.

A single if or else statement is not a block. The breakif command has no effect on such a statement. However, if the single if or else falls within the braces of an outer if construct, breakif breaks the outer if. This is shown in the following example, where the breakif statement passes control to the statement following the closing brace:

if (condition) {
     statements
     if (condition) breakif       /* Breaks the OUTER if */
     statements
}

NOTES

  • If this command is encountered outside an if construct the compiler error “breakif must be inside an if statement” is generated.

  • The special label BREAKIF may be used within the trap clause of a Sculptor command to perform the same function.


EXAMPLE

The breakif commands within the while loops break the outer if loop:

if (tmp.Options ct "A") {
     while (1) {
          ProcessA()
          if (OKAY) then breakif
     }
} else if (tmp.Options ct "B")  {
     while (1) {
          ProcessB()
          if (OKAY) then breakif
     }
}

RELATED TOPICS

break

BREAKIF