IF, ELSE, ELSE IF, ENDIF (FLAG)


 

The IF/ELSE/ELSE IF/ENDIF structures alter the program execution sequence based upon a Flag. These structures use the following formats:

 

(1)

[label]

IF

[NOT] {flag}

 

 

... one or more PL/B instructions

 

 

ELSE

 

 

 

... one or more PL/B instructions

 

 

ENDIF

 

 

 

 

 

(2)

[label]

IF

[NOT] {flag}

 

 

... one or more PL/B instructions

 

 

ELSE IF

[NOT] {flag}

 

 

... one or more PL/B instructions

 

 

ELSE

 

 

 

... one or more PL/B instructions

 

 

ENDIF

 

 

 

 

 

(3)

[label]

IF

[NOT] {flag}

 

 

... one or more PL/B instructions

 

 

ENDIF

 

 

Where:

label

Optional. A Program Execution Label.

flag

Required. One of the condition, pseudo condition or function Flags .

Flags Affected: Function Key

Note the following:

  1. A {flag} or NOT {flag} test is required for the IF or the ELSE IF statements.

  2. ELSEIF may be used in place of ELSE IF.

  3. Each IF structure must have a corresponding ENDIF structure. The ELSE and ELSE IF keywords are optional.

  4. If ELSE IF is used, multiple tests may be executed.

  5. If a FILEPI instruction is active, the FILEPI count is not decremented by this instruction.

  6. If format (1) is used, the instructions between the IF and ELSE structures are executed when the appropriate Flag is as specified or if the expression is evaluated and found TRUE. If the Flag is not as specified or the expression is not TRUE, the instructions between the ELSE and ENDIF structures are executed. After either case, program control resumes at the instruction immediately following the ENDIF structure.

  7. If formats (2) or (3) are used, the instructions between the IF, ELSE IF and ENDIF structures are only executed when the appropriate Flag is as specified or the expression evaluates to TRUE. If not, they are ignored.

  8. If a Function Key Flag is tested for a TRUE condition, it is cleared once taken. Otherwise, the Function Key Flags remain unchanged by these structures.

  9. IF/ELSE structures may be nested within other IF/ELSE or LOOP/UNTIL structures as long as they do not cross the boundary of the structures they are nested within.

  10. Program Control Instructions (such as GOTO, CALL, BRANCH, etc.) may be placed within an IF/ELSE structure. However, they alter the structure's flow.

  11. IF/ELSE structures may be nested thirty-two (32) levels deep. On compilation listings, the level of the nesting is indicated in the left most column of the listing.

Example 1:

 

  

IF

F1

  

DISPLAY

  *N,"F1 was hit";

  

ENDIF

 

 

The message "F1 was hit" is not displayed unless the F1 (Function Key 1) Function Flag is TRUE.

 

Example 2:

 

  

IF

F1

  

DISPLAY

*N,"F1 was hit";

  

ELSE

 

  

IF FKEY

 

  

DISPLAY

*N,"Another Function or ":

  

  

"Control Key was hit";

  

ELSE

 

  

DISPLAY

*N,"No Function or ":

  

  

"Control Key was hit";

  

ENDIF

 

  

ENDIF

 

 

The message "F1 was hit" is displayed if the F1 (Function Key 1) Function Flag is TRUE. If any other Function or Control Key was struck the message "Another Function or Control Key was hit" is displayed. Otherwise, the message "No Function or Control Key was hit" is displayed.

 

Example 3:

 

  

IF

F1

  

DISPLAY

*N,"F1 was hit";

  

ELSE IF

F2

  

DISPLAY

*N,"F2 was hit";

  

ELSE IF

F3

  

DISPLAY

*N,"F3 was hit";

  

ELSE IF

FKEY

  

DISPLAY

*N,"Another Function or ":

  

  

"Control Key was hit";

  

ELSE

 

  

DISPLAY

*N,"No Function or ":

  

  

"Control Key was hit";

  

ENDIF

 

 

The message "F1 was hit" is displayed if the F1 (Function Key 1) Function Flag is TRUE. The message "F2 was hit" is displayed if the F2 (Function Key 2) Function Flag is TRUE. If any other Function or Control Key was struck the message "Another Function or Control Key was hit" is displayed. Otherwise, the message "No Function or Control Key was hit" is displayed.

 

 

See Also: GOTO, Program Control Instructions

 



PL/B Language Reference