:IF... :ELSE... :ENDIF

Use the :IF and :ENDIF script statements to create a conditional block in your script. The script analyzes an expression and runs statements written in the block when a particular condition is met. If the condition is not met, the script either continues with the next line after the conditional block, or runs :ELSE statements if applicable.

Syntax

:IF Condition
[Statements]
[:ELSE]
[Other Statements]
:ENDIF

Parameters

Parameter Description Format
Condition

Defines the mathematical expression that determines whether to run the statements in the conditional block.

Note: You can use the OR keyword to evaluate multiple values against a condition or to chain multiple conditions together. Construct OR conditions using the following syntax: Value Comparison operator Comparison Value [OR Comparison Value...]. A single condition supports a maximum of 13 OR operators.

Example: :IF &DEP# = "EDP" OR "UC4".

Script literals, script variables, script functions, or numbers, yielding either a true or false result.
Statements Defines one or more script statements to execute when the Condition evaluates to true. Script statement
Other Statements Defines one or more script statements to execute when the Condition evaluates to false. Script statement

Comparison Operators

A condition contains one of the following comparison operators:

Operator Short form Rule
= EQ This expression evaluates to true if at least one of the comparison values equals the initial value.
<> NE This expression evaluates to true when none of the comparison values equals the initial value.
< LT This expression evaluates to true if one comparison value corresponds to the defined condition.
> GT This expression evaluates to true if one comparison value corresponds to the defined condition.
<= LE This expression evaluates to true if one comparison value corresponds to the defined condition.
>= GE This expression evaluates to true if one comparison value corresponds to the defined condition.

Important Considerations

Keep the following behaviors and rules in mind when constructing conditional logic:

  • Ensure that you define any script variables used within a condition prior to initiating the conditional block.
  • The inclusion of :ELSE statements is entirely optional.
  • The system supports an unlimited depth for nesting :IF blocks.
  • String comparisons ignore trailing blank spaces, meaning that blank strings of any length consistently evaluate as equal.
  • Conversely, leading zeros are disregarded exclusively during numerical comparisons.
  • Important! The :IF statement evaluates only the first 1024 characters of a string; any character differences extending beyond this limit are not recognized by the system.

Examples

The following comparison of &a with &b returns true because the system eliminates trailing blanks before comparing the strings.

:SET &a = 'a '

:SET &b = 'a'

:IF &a = &b

:PRINT 'true'

:ENDIF

A numerical comparison takes place when both comparison values of a condition have a numerical value (data types signed, unsigned, or float). In all other cases, a string comparison takes place. The following numerical condition evaluates to true:

:IF "0" = "0"

An alphanumeric comparison takes place when there are no numerical values present. Consequently, the following condition evaluates to false:

:IF "0" = "abc"

Script lengths are not checked during the comparison process. The following condition is true because S precedes U in the alphabet:

:IF "Smith" < "UX"

In conditions that incorporate several OR keywords, the evaluation behavior depends on the specified operator. In the following example, the variable must match at least one of the specified values to satisfy the condition.

:IF &WD# = "MON" OR "TUE" OR "WED"

Conversely, the following condition evaluates as true only if the variable does not match any of the three listed values.

:IF &WD# <> "THU" OR "FRI" OR "SAT"

See also: