IF (with Mask)

Conditionally executes Proc commands based on comparison with a specified pattern.

Syntax

IF reference operator (pattern) command

Syntax Elements

reference can be one of the following:

  • A valid form of the A command, except that with a surround character. The A command does not move a value as it does when used alone. The A command is used in an IF command to specify which input buffer parameter is to be tested. Refer to the description of the A command for information on which input buffer parameter the A command references.
  • A direct or indirect reference to a buffer or select register, or a SYSTEM function.

operator performs a value comparison. The operators are:

=Equal to.

# Not equal to.

(pattern) is a pattern format string enclosed in parentheses that tests a parameter for a specified string that can be numeric, alphanumeric or alphabetic. A pattern format string can consist of any of the following:

(nA)Tests for n alphabetic characters.

(nN)Tests for n numeric characters.

(nX)Tests for n alphanumeric characters.

(string)Tests for one or more characters (not numeric).

For example, the pattern (3NABC) specifies a format of three numerics followed by the characters ABC.

command is a valid Proc command.

Operation

The mask feature of the IF command is only meaningful when used with the equal to (=) or not equal to (#) operators.

If there is a zero before any of the pattern types (for example, 0A, 0N, 0X), it means that the number of characters is not important. Any number of characters (or none) is accepted if the characters are the right type.

0X can only be used as the last specification in a pattern.

If the pattern contains a minus sign, then the tested values must have a minus sign.

If the pattern contains a plus sign, then any tested values with either a plus sign or no sign are accepted.

If the pattern does not contain a plus or minus sign, then any sign in the tested values is ignored.

A null value does not match any pattern. For example, it doesn't match (0A), (0N), or (0X). To check for a null using pattern matching, use:

IF %n = ("") command

Alternatively, use:

IF # %n command

Conversely, the following tests for a non-null value:

IF %n command

Do not include spaces in a pattern matching string without putting the spaces in double quotes, for example, use

IF %n = (3N" "3N" "4N)

rather than

IF %n = (3N 3N 4N)

Literal strings can be enclosed in either single or double quotes if required.

Examples

IF &4.2 = (2N3A) GO 10

If the 2nd attribute of file buffer 4 is equal to two numerics followed by three alphabetic characters, then transfer control to the statement with label 10.

IF %4 # (2NXXX) GOSUB 45

If the 4th parameter in the primary input buffer does not equal two numerics followed by XXX, then transfer control to subroutine 45.

IF A = (3N*2A*0N) GO 33

If the current parameter is three numerics, an asterisk, two alphabetics, an asterisk, and any number of (or no) numerics, then transfer control to the statement with label 33.

IF %3 = ((0X)) GO 99

If the 3rd parameter in the primary input buffer is an alphanumeric string enclosed in parentheses, then transfer control to the statement with label 99.