Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
IF SEX = "FEMALE"
IF INCOME > 50000
IF INCOME > 100000
DISPLAY "FEMALE AND INCOME > 100000"
ELSE
DISPLAY "FEMALE AND INCOME > 50000"
END-IF
IF NUMBER-OF-KIDS = 0
DISPLAY " AND SHE HAS NO KIDS!"
END-IF
ELSE
DISPLAY "FEMALE NOT SELECTED"
END-IF
ELSE
PRINT "---> NOT FEMALE"
END-IF
IF cond1
stmts
ELSE
stmts
END-IF
where,
cond1 - can be any arithmetic or logical comparison, or a condition name (88 level);
stmts - can be any single or group of valid COBOL stmts, including other IF stmts.
Remember periods (.) cannot appear within an IF stmt. When using END-IF they should be avoided, although they can be useful in some circumstances.
If using nested IF stmts be sure that each IF has been terminated by its associated END-IF (work from the inside out).
Crox's post is a good example of a complex IF stmt, covering most, if not all of what you can do in one.
Another aspect of complex condition testing is mixing IFs and EVALUATEs. I find it helps to make the code a bit more "readable":
EVALUATE TRUE ALSO TRUE
WHEN AGE-IS-UNDER-30 ALSO SEX-IS-MALE
IF INCOME > 50000
PERFORM 1000-SPAM-HIM
END-IF
WHEN STATE = NJ ALSO NO-SPAM-SET
PERFORM 1000-SPAM-HIM 100 TIMES
END-EVALUATE
EVAL data-name
EVAL TRUE
EVAL FALSE
EVAL data-name ALSO TRUE ALSO FALSE.....
or in any combination thereof
The EVAL (use the full word) is followed by one or more WHEN stmts followed by an END-EVAL. The ALSO is treated as a logical AND; the OR I'll show later. Let's take that last EVAL:
EVAL WS-AGE ALSO TRUE ALSO FALSE
WHEN 18 THRU 25 ALSO WS-WT > 200 ALSO MALE
PERFORM 1000-ENROLL-IN-FBALL-PGM
END-EVAL