Conditionally executing statements

if

Conditionally execute statements


SYNTAX

if condition [then] {

 statements

} [else {

 statements

}]

The ifthenelse construct tests the condition after the if. If this is found to be true, the statements following the then are executed. If the optional else clause is included, and condition is found to be false, then the statements following the else are executed.

Any of the statements following the then or the else may be another if statement with an optional else clause, and so on.

The word then is optional and may be omitted.

Either or both sets of statements may consist of a single statement, which may be placed on a single line with the braces omitted.

condition

The condition may include all supported arithmetical, relational and logical operators. These are listed under Table of operators, together with their order of precedence. Parentheses may be used to force a different order of evaluation.

If condition is an expression without a conditional test (e.g. 100; 34 + 6; “ABC”; tmp_Field), it is evaluated in the following way:

Numeric

An expression that evaluates to zero is false; one that evaluates to anything else is true.

Alphanumeric

An expression that produces a null string, or a string containing only spaces, is false; all other alphanumeric expressions are true.

statements

A block of Sculptor code.

The breakif command can be used from within the statements to transfer control to the end of an if construct. In addition, the BREAKIF label may be used in the trap clause of a Sculptor command to transfer control to the end of an if construct.


NOTES

  • If 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.

  • If an else clause is placed on a new line after the closing brace of the if statements, a backslash must be placed after this brace to indicate a line continuation.


EXAMPLES

Single if statement

if (EventCode <> EV_BUTTON_CLICKED) then return

Nested ifs:

if (SelectedFile <> "") {
     if (Display(SelectedFile) <> OKAY) {
          error "Selected file could not be accessed"
     }
}

Block of if statements with single else statement:

if (IsAlphaField and WidthInChars) {
     Pixels = MaxChar + (WidthInChars - 1) * AvgChar
     Count = WidthInChars
     while (Count-- > 3 and MaxChar-- > AvgChar) {
          Pixels--
     }
} else {
     Pixels = WidthInChars * AvgChar
}

RELATED TOPICS

do

for

switch

while

breakif