Exercises - using comparison expressions, Logical (boolean) operators – IBM SC34-5764-01 User Manual

Page 47

Advertising
background image

Exercises - Using Comparison Expressions

1. Based on the preceding example of using a comparison expression, what result does the language

processor produce from the following lunch costs?

Yesterday's Lunch

Today's Lunch

4.42

3.75

3.50

3.50

3.75

4.42

2. What is the result (0 or 1) of the following expressions?

a. "Apples" = "Oranges"
b. " Apples" = "Apples"
c. " Apples" == "Apples"
d. 100 = 1E2
e. 100 \= 1E2
f. 100 \== 1E2

ANSWERS

1. The language processor produces the following sentences:

a. Today's lunch cost the same or less than yesterday's.
b. Today's lunch cost the same or less than yesterday's.
c. Today's lunch cost more than yesterday's.

2. The expressions result in the following. Remember 0 is false and 1 is true.

a. 0
b. 1
c. 0 (The first " Apples" has a space.)
d. 1
e. 0
f. 1

Logical (Boolean) Operators

Logical expressions, like comparison expressions, return 1 (true) or 0 (false) when processed. Logical
operators combine two comparisons and return 1 or 0 depending on the results of the comparisons.

The logical operators are:

/****************************** REXX *********************************/
/* This program compares what you paid for lunch for two

*/

/* days in a row and then comments on the comparison.

*/

/*********************************************************************/

PARSE PULL yesterday

/* Gets yesterday's price from input stream */

PARSE PULL today

/*

Gets today's price

*/

IF today > yesterday THEN

/* lunch cost increased */

SAY "Today's lunch cost more than yesterday's."

ELSE

/* lunch cost remained the same or decreased */

SAY "Today's lunch cost the same or less than yesterday's."

Figure 12. Example Using a Comparison Expression

Using Variables and Expressions

Chapter 3. Using Variables and Expressions

25

Advertising