Professional Documents
Culture Documents
ch08 - 97 If Statement
ch08 - 97 If Statement
Programming
“Copyright @ 2000 John Wiley & Sons, In. All rights
reserved. Reproduction or translation of this work beyond
Nancy Stern that permitted in Section 117 of the 1976 United States
Copyright Act without the express permission of the
copyright owner is unlawful. Request for further
Hofstra University
information should be addressed to the permissions
Department , John Wily & Sons, Inc. The purchaser may
make back-up copies for his/her own use only and not for
distribution or resale. The Publisher assumes no
responsibility for errors, omissions, or damages, caused
Robert A. Stern by the use of these programs or from the use of the
information contained herein.”
Nassau Community
College 9th Edition
PowerPoint Presentation:
Richard H. Baum, Ph.D.
DeVry Institute of Technology
Strutured COBOL Programming, Stern & Stern, 9th Edition
CHAPTER 8
Decision Making Using the
IF and EVALUATE
Statements
ADD 1 TO XX
END-IF
Solution: You cannot say:
GO TO CONTINUE
3. IF A EQUALS B
MOVE 1 TO A
END-IF
4. IF A IS LESS THEN B
MOVE 2 TO CODE1
END-IF
5. IF C = D
MOVE 0 TO COUNTER.
ELSE
6. IF C = D
MOVE 0 TO COUNTER
ELSE
NEXT SENTENCE.
Solution: ELSE NEXT SENTENCE, although not
incorrect, is unnecessary. Note that END-IF
cannot be used with NEXT SENTENCE (unless
your compiler has an enhancement that permits
it) but can always be used with CONTINUE.
• With A = 2, B = 2, C = 3, D = 4, E = 5, and
F = 6, 600-PARA-1 will be executed
because A = B.
Class Test
• We can test for the type of data in a field
by coding IF identifier- 1 IS NUMERIC or IF
identifier-1 IS ALPHABETIC.
• If the ELSE option is executed with the
NUMERIC class test, then either the field
contains alphabetic data (only letters
and/or spaces) or it contains alphanumeric
data, meaning any possible characters.
IF NAME-IN IS ALPHABETIC-LOWER
THEN
PERFORM 600-LOWER-CASE-RTN
END-IF
2. Other Tests
a. Sign test
IF identifier-1 IS {POSITIVE}
{NEGATIVE}
{ZERO}
– Identifier-1 must have an S in its PIC clause
if it is to store data with a negative value.
b. Class Test
IF identifier-1 IS {NUMERIC}
{ALPHABETIC}
c. Negated Conditionals
(1) A test can be preceded with NOT to test
the negative conditional.
(2) IF NOT (A = B OR A = C) is the same as
IF A NOT = B AND A NOT = C.
Strutured COBOL Programming, Stern & Stern, 9th Edition
CHAPTER SUMMARY
C. Condition-Names
1. Coded on the 88-level directly
following the field to which it relates.
For example:
05 CODE-IN PIC X.
88 OK-CODE VALUE '6'.