If...Endif. DORIC 9.65, INFO-Text software
Publicitate
Publicitate
IF...ENDIF
.
IF
.
ELSE
.
.
ENDI
F logical_expression
evaluates logical expressions within an INFO program or input form and executes statements according to the results of the evaluation.
argument notes
logical_expression statement that INFO evaluates.
n
IF...ENDIF denotes the beginning and ending of IFstatement logic.
n
ELSE directs INFO if the logical expression is false.
When you include an ELSE statement and the expression is false at runtime, the control passes immediately to the statement that follows the ELSE.
n
The IF command evaluates the logical expression(s) and uses the results of that evaluation to determine the next instruction to be executed, as follows:
1) If the expression(s) are evaluated to be true and you have not included the ELSE, INFO executes the commands between the IF and ENDIF.
2) If the expression(s) are evaluated to be true and you have included an ELSE command, INFO executes the commands between IF and ELSE, then executes the first command following the ENDIF command (unless GOTO,
RUN, END or DONE are specified).
3) If the expression(s) are evaluated to be false and you have not included an ELSE command, INFO executes the first command following the ENDIF command.
INFO Reference Manual Commands 273
IF...ENDIF
4) If the expression(s) are evaluated to be false and you have included an ELSE command, INFO executes the commands following the ELSE command.
n
You can nest up to 100 IF-ENDIF pairs within one IF statement.
n
You can use an IF...ENDIF sequence in an odd- or an even-numbered program section but not across sections.
n
If you include an IF statement in an odd program section, only use system variables in the IF logical expression, because referencing data file items causes only the values from the last record in the selected set to be tested.
To test the value of an item in a selected record or corresponding related record, first MOVE or CALCULATE the item into an appropriate system variable. In the following example, the MOVE command uses the value of
PART-NO from the first selected record:
10005 RESELECT BY $RECNO = 1
10006 MOVE PART-NO TO $CHR1
10007 ASELECT
10008 IF $CHR1 EQ '9999' n
Be careful if using SELECT, RELATE, or FORMAT commands within an IF...ENDIF sequence. During the program compilation, INFO's compile processor does not recognize when a statement is executed conditionally, and assumes that each statement is executed as it is encountered. Therefore, when it encounters a conditional
SELECT, for example, the compiler treats all subsequent processing, until the next selection statement, as though the selected file were current, even after it leaves the conditional command sequence that actually uses that file at runtime.
274 Commands INFO Reference Manual
IF...ENDIF
10000 PROGRAM SECTION ONE
10001 SELECT FILE1
10002 IF $NUM1 EQ 1
10003 SELECT FILE2
10004 DISPLAY SYSTEM
10005 ELSE
10006 DISPLAY CUST
10007 ENDIF
example
The compiler assumes
FILE2 is selected
When INFO compiles the command DISPLAY CUST in the above example, it assumes that FILE2 is the selected file, although at runtime, FILE1 is selected. If CUST is not an item in FILE2, a compilation error occurs. If CUST is coincidentally an item in, the program compiles and executes, but the results may be wrong.
20001 PROGRAM SECTION TWO
20002 IF YTD-AMT LE 100.00
20003 CALCULATE NET = YTD-AMT * $NUM10
20004 ELSE
20005 IF YTD-AMT LE 500.00
20006 CALCULATE NET = YTD-AMT * $NUM20
20007 ELSE
20008 IF YTD-AMT LE 1000.00
20009 CALCULATE NET = YTD-AMT * $NUM30
20010 ENDIF
20011 ENDIF
20012 ENDIF
INFO Reference Manual Commands 275
Descarcă
Publicitate