IF (Multivalued)
Compares an expression with one of several different expressions or values, then conditionally executes one of several commands.
Syntax
IF reference operator expression{]expression}... command{]command]}...
Syntax Elements
reference 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 explanation 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.
expression One of the following:
- A direct or indirect reference to a buffer or select register.
A string containing one or more nonblank characters.
If the string contains embedded blanks or the first character is an exclamation mark (!), it must be enclosed in single or double quotes.
- A format string enclosed in parentheses that tests a parameter for a specified string that can be numeric, alphanumeric or alphabetic.
Refer to the IF (with Mask) command for more information on patterns.
] Represents a value mark (CTRL+]).
command A valid Proc command.
Operation
The multivalued feature of the IF command is only meaningful when used with the equal to (=) or not equal to (#) operators. It permits one IF statement to do the work of many single IF statements.
Multiple expressions must be separated with value marks (CTRL+]), and can be any expression that would normally be placed after an operator.
Multiple commands are formed like multiple expressions. Proc commands are separated with value marks (CTRL+]). Any valid Proc command can be used.
Note
Do not use O or X as commands unless they are the last command in the series or they will cause other commands in the series to be ignored.
If you use the equal to (=) operator, a logical OR is performed on the expressions. If the reference is equal to any expression in the multiple expression string, the condition is true. If more than one expression is true, the command corresponding to the first true expression is executed. If there are more expressions than commands and the true expression does not have a corresponding command, the last command in the IF statement is executed. If there are more commands than expressions, the remaining commands are ignored.
If you use the not equal (#) operator, a logical AND is performed on the expressions. The reference must not equal any expression in the multiple expression string for the condition to be true. In this case, the first command specified is executed. Further commands are not meaningful with the # operator.
Special cases of the G and GOSUB commands apply when performing multiple expression comparisons. Instead of repeating each GO with each multivalued command, they can be combined in one command, for example:
IF A = A]B]25]500 GOSUB 10]20]30]40
If a direct or indirect reference to a buffer or select register specifies a parameter with multivalues, the same Proc statement is executed no matter which of the multivalues is true. Therefore, each value does not access a different command as it would have if it had been coded directly into the IF statement.
It is also possible to perform multiple conditional tests in one Proc statement. For example:
IFN %2 ] 1 IFN %2 [ 10 ONUMBER IS 1 THRU 10
If the value in the 2nd parameter in the primary input buffer is equal to or greater than 1 and if the value in the 2nd parameter in the primary input buffer is equal to or less than 10, the string following the O command is output to the terminal.
Case Insensitivity
If data case insensitive mode is selected (see Case Sensitivity), case is ignored when comparing strings.
Examples
IF &4.2 = A]B]C]D G 10
In this example, if the 2nd attribute in file buffer 4 is equal to A, B, C or D then control transfers to the statement with label 10.
IF %4 # (2N)]"AA"]"B XXX"]"" GOSUB 45
If the 4th parameter in the primary output buffer is not equal to two numerics, and not equal to the string AA, and not equal to the string B XXX, and it is not a null, then control transfers to subroutine 45.
IF %2 = 33]&3.2]%4]!2 GO 40
If the 2nd parameter in the primary input buffer is equal to 33, or equal to the 2nd attribute in file buffer 3, or equal to the 4th parameter in the primary input buffer, or equal to the next value in select register 2, then control transfers to the statement with label 40.
IF &3.1 = A]B]C G 10]15]20
If the 1st attribute in file buffer 3 equals A, B or C, then control passes to the statements with labels 10, 15 or 20, respectively.
IF %5 = 0]($0N) GO 10]MV #3 "VALUE ="
If the 5th parameter in the primary input buffer equals 0, control transfers to the statement with label 10. If the 5th parameter in the primary input buffer is equal to a dollar sign ($) and any (or no) numerics, then the string "VALUE =" is moved into the 3rd parameter of the output buffer.