pTAL Reference Manual (G06.24+, H06.09+, J06.03+)
Example 14 CASE Expression
INT x, a, b, c, d;
!Code to initialize variables
x := CASE a OF
BEGIN
b; ! If a is 0, assign value of b to X.
c; ! If a is 1, assign value of c to X.
d; ! If a is 2, assign value of d to X.
OTHERWISE -1; ! If a is any other value,
END; ! assign -1 to x.
IF
The IF expression selects one of two expressions, usually for assignment to a variable.
condition
is either:
• A conditional expression
• An INT arithmetic expression. If the result of the arithmetic expression is not 0, the
condition is true. If the result is 0, condition is false.
expression-1, expression-2
are expressions of any data type, but their data types must be compatible:
• Every data type is compatible with itself.
• String and unsigned (1-16) data types are compatible with INT
• Unsigned (17-32) data types are compatible with INT(32)
• All fixed-point data types are compatible with each other; however, if expression-1
and expression-2 are differently scaled fixed-point expressions, the data type of the
CASE expression is the data type of the fixed-point expression whose scale factor is largest.
For example, these return statements are equivalent:
INT i; INT i;
FIXED(-2) f2; FIXED(-2) f2;
FIXED(-3) f3; FIXED(-3) f3;
FIXED(-4) f4; FIXED(-4) f4;
FIXED(-2) proc p; FIXED(-2) PROC p;
BEGIN BEGIN
RETURN CASE i OF RETURN CASE i OF
BEGIN BEGIN
f3; $SCALE(f3,1);
f2; f2;
OTHERWISE f4 OTHERWISE $SCALE(f4,2)
END END
END END
If condition is true, the result of the expression-1 becomes the result of the overall IF
expression.
If condition is false, the result of expression-2 becomes the result of the overall IF expression.
Special Expressions 87