IF

Top  Previous  Next

 

The IF command allows conditional execution of sentences within paragraphs.

 

 

Format

 

IF value.1 rel.op value.2 THEN sentence

 

where

 

value.1, value.2are two items to be compared. These may be inline prompts, constants or @­variables as described below.

 

rel.opis the relational operator to be applied to the two values.

 

sentenceis the sentence to be executed if the condition is true.

 

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:

 

<

LT

BEFORE

LESS


<=

LE

=<



=

EQ

EQUAL



>=

GE

=>



>

GT

AFTER

GREATER


#

NE

<>

><

NOT

LIKE

MATCHES

MATCHING



UNLIKE

NOT.MATCHES




~

SAID

SPOKEN



 

The function of each relational operator as applied to values of different types is the same as its QMBasic equivalent

 

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.

 

 

Example

 

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.