Exercises - using logical expressions, Concatenation operators, Using concatenation operators – IBM SC34-5764-01 User Manual
Page 49
\___________________/
/
true
/
\_____________________________/
true
As a result, when you run the program, it produces the result:
Go skiing.
Exercises - Using Logical Expressions
A student applying to colleges has decided to evaluate them according to the following specifications:
IF
(inexpensive | scholarship) & (reputable | nearby)
THEN
SAY
"I'll consider it."
ELSE
SAY
"Forget it!"
A college is inexpensive, did not offer a scholarship, is reputable, but is more than 1000 miles away.
Should the student apply?
ANSWER
Yes. The conditional instruction works out as follows:
IF
(inexpensive | scholarship) & (reputable | nearby)
THEN ...
\__________/ \___________/
\_________/ \______/
true
false
true
false
\___________/
\_________/
true
true
\_________________________/
true
Concatenation Operators
Concatenation operators combine two terms into one. The terms can be strings, variables, expressions, or
constants. Concatenation can be significant in formatting output.
The operators that indicate how to join two terms are as follows:
Operator
Meaning
blank
Concatenates terms and places one blank between them. If more than one blank separates terms,
this becomes a single blank. For example:
SAY true
blue
/* result is TRUE BLUE */
||
Concatenates terms with no blanks between them. For example:
(8 / 2)||(3 * 3)
/* result is 49
*/
abuttal
Concatenates terms with no blanks between them. For example:
per_cent'%'
/* if per_cent = 50, result
is 50%
*/
You can use abuttal only with terms that are of different types, such as a literal string and a
symbol, or when only a comment separates two terms.
Using Concatenation Operators
One way to format output is to use variables and concatenation operators as in the following example.
Using Variables and Expressions
Chapter 3. Using Variables and Expressions
27