IF,ELSE,ELSE IF,ENDIF


ANSI

 

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

 

(1)

[label]

IF

[NOT] {condition}

 

 

... one or more PL/B instructions

 

 

ELSE

 

 

 

... one or more PL/B instructions

 

 

ENDIF

 

 

 

 

 

(2)

[label]

IF

[NOT] {condition}

 

 

... one or more PL/B instructions

 

 

ELSE IF

[NOT] {condition}

 

 

... one or more PL/B instructions

 

 

ELSE

 

 

 

... one or more PL/B instructions

 

 

ENDIF

 

 

 

 

 

(3)

[label]

IF

[NOT] {condition}

 

 

... one or more PL/B instructions

 

 

ENDIF

 

 

Where:

label

Optional. A Program Execution Label.

condition

Required. A valid check for a Flags or Expression.

Flags Affected: Function Key

Note the following:

  1. A {condition} or NOT {condition} 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. The Function Key Flag is not reset when checked in an expression.

  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.

 

 

See Also: Example Code, GOTO, Program Control Instructions

 



PL/B Language Reference GOTO LOADMOD