IF, ELSE and EVALUATE
| IF END-IF | |
| ELSE | |
| EVALUATE |
IF END-IF
IF runs a sentence when its condition is true. END-IF closes the block, and periods belong to the last sentence inside, not to END-IF:
IF WS-SCORE >= 90
MOVE "A" TO WS-GRADE
END-IF.
ELSE
ELSE adds the false path. Nest IF sentences inside each other, and keep the indentation one level per block so END-IF matches its IF:
IF WS-SCORE >= 90
MOVE "A" TO WS-GRADE
ELSE
IF WS-SCORE >= 80
MOVE "B" TO WS-GRADE
END-IF
END-IF.
EVALUATE
EVALUATE is the case statement. WHEN matches a value or condition, and WHEN OTHER catches everything else. It replaces deep nesting with a flat list:
EVALUATE WS-GRADE
WHEN "A" DISPLAY "Excellent"
WHEN "B" DISPLAY "Good"
WHEN OTHER DISPLAY "Retry"
END-EVALUATE.
Next: PERFORM loops
Article author: Arthur Isaev