: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

Notes:

Important! The :IF statement does not recognize differences in characters beyond the first 1024 characters in a string.

A condition contains one of the following comparison operators:

Operator

Short form

Rule

=

EQ

This expression is "True" if at least one of the comparison values equals the Value.

<>

NE

This expression is "True" when none of the comparison values equals the Value.

<

LT

This expression is "True" if one comparison value corresponds to the defined condition.

>

GT

<=

LE

>=

GE

Examples

  • The following comparison of &a with &b returns true because the trailing blanks are eliminated 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 condition is true:

    :IF "0" = "0"

    An alphanumeric comparison takes place when there are no numerical values.

    The following condition is false:

    :IF "0" = "abc"

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

    :IF "Smith" < "UX"

    In conditions that include several OR keywords, the behavior depends on the operator.

    In the following example, one of the values must apply in order to meet the condition.

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

    The following condition is only met if the variable does not comply with any of the three values.

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

    See also: