Ex
4.1
0
4.4
FALSE
TRUE
TRUE
Ex
4.2
TRUE
TRUE
FALSE (the
UPB t[2:] is 5
Ex
4.3
TRUE
TRUE
TRUE
TRUE. It is inadvisable to created compuound
conditions with this sort of complexity simply because the condition
is so difficult to understand. You should particularly avoid compound
conditions with NOT in front of the various parts.
FALSE
Ex
4.4
TRUE
4 <= 2
a <= b OR b <= c
x /= y AND x /= z
Ex
4.5
IF x < pi
THEN print("Yes")
ELSE print("No")
FI
Ex
4.6
FOR i TO 96
DO
print(i*3);
IF i MOD 16 = 0
THEN print(newline)
FI
OD
Ex
4.7OREL is only elaborated if
the first yields FALSE.
PROGRAM ex4 7 CONTEXT VOID
USE standard
BEGIN
INT a = 3, b = 5, c = 4;
IF
IF a > b
THEN TRUE
ELSE b > c
FI
THEN print("Ok")
ELSE print("Wrong")
FI
END
FINISH
Ex
4.8p must yield
INT, not BOOL.
Ex
4.9
PROGRAM ex4 9 CONTEXT VOID
USE standard
CASE SIGN x + 2
IN
print("x < 0.0"),
print("x = 0.0"),
print("x > 0.0")
ESAC
FINISH
Ex
4.10TRUE and
FALSE
Ex
4.11
TRUE
TRUE
TRUE
FALSE
FALSE
FALSE
Ex
4.12THEN. Also replace the
ESAC with FI.
Ex
4.13TFTFTFTFTF
Ex
4.14
IF m < 10
THEN print("Units")
ELIF m < 100
THEN print("Tens")
ELIF m < 1000
THEN print("Hundreds")
ELSE print("Too big")
FI
Ex
4.15
print((card|"Ace","two","three",
"four","five","six",
"seven","eight","nine",
"ten","Jack","Queen",
"King"))
Sian Mountbatten 2012-01-19