Skip to main content

IF, IFN

Conditionally executes a command.

Synopsis

IF condition command
IF condition label
IFN condition command
IFN condition label

where condition:
x {= | # | < | >} y
x {= | #} (patcode)
[#]E
[#]S[n]

Arguments

condition A condition that resolves to a boolean value. If TRUE (1), command is executed. If FALSE (0), command is not executed.
command The command to execute if condition=1 (TRUE).
label An integer specifying the location to go to if condition=1 (TRUE).

Description

The IF PROC command applies a boolean test on a condition statement, and, if the condition is true, either executes the specified command, or goes to the specified label location. A condition is true if any one of the value comparisons are true.

IF performs a string condition comparison. IFN performs a numeric condition comparison.

A condition can use the = (equal to) or # (not equal to) operator. The following conditions are supported:

  • x {= | #} y An equality condition compares a value to a value. A value can be a literal, an A command, or a reference to a buffer or select list. When used with IF an A reference cannot contain a char delimiter character. If x is a reference, only the first value found in the buffer or select list is compared to y. If y is a reference, all of the values found in the buffer or select list are compared to x.

  • x {= | #} (patcode) A pattern match condition compares a value to a pattern match code. A pattern match code is enclosed in parentheses; for example, (3A). A=alphabetic characters; N=numbers. If x is a reference, only the first value found in the buffer or select list is matched to the pattern code.

  • [#]E An error condition tests whether an error code exists (E) or does not exist (#E). Because E contains the error code value, you can also perform an IF test on the value of the error code: E < 1. Error codes are integers beginning with 260, through 277.

  • [#]Sn A select list condition tests whether the specified select list is active. For example, S3 determines if select list 3 is active; #S3 determines if select list 3 is not active.

Compound IF Expressions

You can use the ] character to create compound IF expressions. In a compound expression, the right side of the condition consists of two (or more) match conditions, each of which has its corresponding command or label.

In the following example, the value of x is first compared to all of the values in %3; if any of these match, command1 is executed. If x does not match %3, x is then matched with all of the values in %4; if any of these match, command2 is executed.

IF x = %3]%4 command1]command2

In the following example, the value of x is first compared to the literal Foo; if this is a match, a goto operation is performed to label 100. If x does not match Foo, x is then matched with Bar; if this is a match, a goto operation is performed to label 200.

IF x = Foo]Bar 100]200

See Also

  • A PROC command

  • GO PROC command

  • P PROC command

FeedbackOpens in a new tab