The if command performs a conditional expression.
Syntax
if {#} e {operator message.num} command if {#} s command if {#} a{param.num}{,n} {operator {’string’ | (pattern.match)}} command |
First form: The e operand tests for a specified message number from the dm,messages, file. If true, the specified PROC command is performed.
Second form: The s operand tests for an active list. It can be used after a select, sselect, qselect, or get-list command.
Third form: This tests the contents of the buffer location specified in the a{param.number} expression with any logical or pattern matching operator, and performs the specified PROC command if successful. The optional ,n argument allows only the specified number of characters to be compared.
Parameter(s)
# |
The not equal to operator reverses the sense of the condition. |
|
operator |
The relational operators available are: |
|
= |
Equal to |
|
# |
Not equal to |
|
< |
Less than |
|
> |
Greater than |
|
[ |
Less than or equal to |
|
] |
Greater than or equal to |
|
message.num |
The error number returned, if any. Error numbers are the item-IDs in the errmsg file. If no message number is specified, then any message number causes this to be true. |
|
command |
The Proc command to be executed if the condition is met; otherwise, this proc command is skipped. |
|
a{param.num}{,n} |
Specifies that an a command be used as the test condition. The parameters are not moved to the active output buffer. However, the buffer pointer is repositioned as specified by the a command. See a Command for more information. |
|
string |
A literal string. |
|
pattern.match |
The character pattern to match. The pattern must be enclosed in parentheses. The n specifies the length of the match operator field. A length specification of 0 allows variable length input, but tests as true only if all characters match the character type (numeric/alphabetical/alphanumeric). The following pattern forms are: |
|
na |
Accepts n alphabetical characters only. |
|
nn |
Accepts n numerical characters only. |
|
nx |
Accepts n of any characters. |
|
’string’ |
Accepts literal string. The string must be surrounded by single quotation marks (’). |
Description
Comparisons are performed one character at a time from left to right. For the purposes of comparison, letters are converted to uppercase—so uppercase and lowercase letters are equal.
If no unequal characters are found, the two strings are considered equal. If the two strings are of unequal length, but the shorter string is otherwise identical to the longer string, the longer string is greater than the shorter string. If the two strings are unequal, then the comparative ASCII values of the two characters decide which string is greater than and which is less than.
The if commands can be nested, forming a logical and condition:
if a = 2 if b > 10 if c < 19 go 99 |
Example(s)
Checks for error message 401 and stops/returns if present.
if e = 401 xno items were selected... |
Checks for 3 numbers, a dash, 2 numbers, a dash, and 4 more numbers.
if a # (3n’-’2n’-’4n) oinvalid ss#. |
Checks the currently active input buffer location for the presence of the letter x.
if a = x xdone. |
Checks the currently active input buffer location for the presence of 0 or more numbers.
if a = (0n) go 10 |
Checks the first character of the currently active input buffer location for the presence of the letter q.
if a1,1 = q x proc terminated voluntarily |
Checks for the absence of a value in the first position of the currently active input buffer.
if # a1 go 10 |
See Also
go Command, Primary Input Buffer, PROC Processor, Secondary Input Buffer