IF |
|
|
The IF command allows conditional execution of sentences within paragraphs.
Format
IF value.1 rel.op {NO.CASE} value.2 THEN sentence IF EXISTS filename id THEN sentence IF NOT.EXISTS filename id THEN sentence IF value.1 IN {NO.CASE} value.2, value.3... THEN sentence IF value.1 NOT.IN {NO.CASE} value.2, value.3... THEN sentence
where
In its first form, the IF command compares two values using a specified relational operator. The values may be inline prompts, constants or @-variables. Null strings or string constants which include spaces should be enclosed in single or double quotation marks. The value.1 and value.2 items need to be quoted if they may evaluate to strings with embedded spaces or to reserved words such as the relational operators.
Note that because inline prompts are evaluated as the first stage of processing a command, an inline prompt in the sentence component of an IF statement will be evaluated before determining whether the condition is True. To avoid this problem, a statement such as IF @SYSTEM.RETURN.CODE = 1 THEN LIST <<Filename>> must be written as IF @SYSTEM.RETURN.CODE # 1 THEN GO SKIP LIST <<Filename>> SKIP:
The relational operator may be any of:
The function of each relational operator as applied to values of different types is the same as its QMBasic equivalent
The forms of IF using EXISTS or NOT.EXISTS check the existence or non-existence of a record. The filename and id values are identify the file and record id. If the record id contains spaces or other special characters, it must be enclosed in quotes.
The forms of IF using IN or NOT.IN test whether value.1 is in or not in the list of literal values.
The optional NO.CASE qualifier performs a case insensitive comparison.
Multiple conditions may be linked by the keywords AND and OR. These operators are of equal priority and are evaluated left to right. Use of brackets to alter the order of interpretation is not supported in the IF command.
Examples
PA BASIC <<Program name>> IF @SYSTEM.RETURN.CODE = 1 THEN CATALOGUE <<Program name>>
This paragraph compiles a QMBasic program (the record name of which it obtains using an inline prompt) and, if successful, adds the program to the system catalogue. In this example, use of the inline prompt in the conditioned statement is not a problem as the prompt was displayed as part of processing of the previous line.
IF EXISTS VOC <<@LOGNAME>> THEN <<@LOGNAME>>
This example shows how it is possible to produce the effect found in some other multivalue products where each user may have a separate initialisation script instead of the single LOGIN paragraph used in QM. Inserting this line in the LOGIN paragraph would check if there was a paragraph with the same name as the user's login name and, if so, execute it.
IF @TTY IN 'phantom', 'startup', 'vbsrvr' THEN STOP
The above command used in the LOGIN paragraph would terminate the paragraph if the value of the @TTY variable was any of the listed values. |