Rational Developer for System z
COBOL for Windows, Version 7.5, Programming Guide


Example: EVALUATE using multiple WHEN phrases

The following example shows that you can code multiple WHEN phrases if several conditions should lead to the same action. Doing so gives you more flexibility than using only the THRU phrase, because the conditions do not have to evaluate to values in a range or have the same class.

EVALUATE MARITAL-CODE
  WHEN “M”
    ADD 2 TO PEOPLE-COUNT
  WHEN “S”
  WHEN “D”
  WHEN “W”
    ADD 1 TO PEOPLE-COUNT
END-EVALUATE

The following nested IF statements represent the same logic:

IF MARITAL-CODE = “M” THEN
  ADD 2 TO PEOPLE-COUNT
ELSE
  IF MARITAL-CODE = “S” OR
     MARITAL-CODE = “D” OR
     MARITAL-CODE = “W” THEN
       ADD 1 TO PEOPLE-COUNT
  END-IF
END-IF

Terms of use | Feedback

Copyright IBM Corporation 1996, 2008.
This information center is powered by Eclipse technology. (http://www.eclipse.org)