Chapter 8. DECISION-MAKING USING THE IF AND EVALUATE STATEMENTS

CHAPTER OBJECTIVES

Upon completion of this chapter, you should be able to

  • Explain how numeric and alphanumeric fields are compared.

  • Describe the rules for forming numeric and alphanumeric literals.

  • Describe and demonstrate the use of the various IF statements.

  • Describe and demonstrate the use of the EVALUATE statement.

LOGICAL CONTROL STRUCTURES

In this chapter we focus on some instructions that enable the program to make decisions that affect the order in which statements are executed. Such instructions are referred to as logical control structures.

The full range of logical control structures used in any program, regardless of the programming language, is

  1. Sequence.

  2. Selection (IF-THEN-ELSE).

  3. Iteration (PERFORM).

  4. Case (EVALUATE).

In this chapter, we focus first on the IF-THEN-ELSE structure that permits programs to execute one or more instructions depending on the contents of fields. Then, we present the case structure, which is executed using the EVALUATE verb. In the next chapter, we consider iteration in detail, focusing on the PERFORM statement and its options.

THE IF CONDITIONAL STATEMENT

A conditional statement performs operations depending on the existence of some condition. Such statements generally begin with the word IF and are called IF-THEN-ELSE or selection structures.

THE INSTRUCTION FORMAT FOR AN IF STATEMENT

The basic instruction format for IF statements is

Instruction Format

THEN is Optional. The THEN clause in the instruction ...

Get PROGRAMMING IN COBOL/400: 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.