IF

Allows conditional execution of Proc commands based on the presence or value of an expression.

Syntax

IF {#} reference command

or

IF reference operator expression command

Syntax Elements

# Tests for the absence of a value.

reference Can be one of the following:

  • A valid form of the A command, except the A command with a surround character.

    The A command does not move a value as it does when used alone. If 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.

< Less than.

> Greater than.

[ Less than or equal to.

] Greater than or equal to.

expression Can be one of the following:

  • A direct or indirect reference to a buffer or select register.
  • A string of 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.

command A valid Proc command.

Operation

If the condition reference operator expression is true, the command at the end of the IF statement is executed; then processing continues with the next line.

If the condition reference operator expression is false, the command at the end of the IF statement is skipped and processing continues with the next line.

The A command in an IF statement specifies which input buffer parameter is to be tested. The value is not moved to the output buffer but the input buffer pointer is repositioned.

Used alone, the A command or a reference tests for the existence of a value. Used with the not equal symbol (#), the A command or a reference tests for the absence of a value.

If you use a direct or indirect reference to a buffer or select register, the buffer pointers do not change position.

A character-by-character, left-to-right comparison is performed on each condition. If the strings do not contain exactly the same characters, then the string with the higher value is greater. For example, "AAB" is greater than "AAAB", and 3 is greater than 132.

Use the IFN command for numeric comparisons.

Case Insensitivity

If data case insensitive mode is selected (see Case Sensitivity), case is ignored when comparing strings.

Examples

IF %3 = ABC OYES
RI

If the 3rd parameter in the primary input buffer is equal to ABC, print YES, then clear the buffer. Otherwise, just clear the buffer.

IF # &2.3 GO 30
MV #3 &2.3
.
30 OENTER NAME+
IP:#3

If there is no value in the 3rd parameter of file buffer 2, control transfers to the statement with label 30. Otherwise, the value in the 3rd parameter of file buffer 2 is moved to the 3rd parameter of the active output buffer.

100 IP?%1
IF %1 = &4.2 G 200
MV #3 %1
.
200 OVALUE ALREADY EXISTS
OTRY AGAIN +
G 100

If the input value is the same as the 2nd attribute in file buffer 4, then control transfers to the statement with label 200. Otherwise, the input value is moved into the 3rd parameter of the active output buffer.

IF &4.7 # C G 10
T "ACCOUNT ",&4.0,"HAS A CREDIT CHECK CODE!"
T "CONTINUE",+
RI
IP?
IF # A G 10
IF A(1,1) = Y G 10
X
10 S2

If the 7th attribute in file buffer 4 is not equal to 'C', then set the input buffer pointer to the 2nd parameter, otherwise indicate the presence of a check code. If a RETURN or if the 1st character input is 'Y', then set the buffer pointer to the 2nd parameter, otherwise exit to TCL.