TAL Programmer's Guide

Conditional Expressions
Using Expressions
5–24 096254 Tandem Computers Incorporated
Controlling Program Execution
You use relational expressions in control statements to determine the flow of execution.
This example shows how you can direct program execution based on comparisons
using signed and unsigned operators:
INT a := –2, !Unsigned value = %177776
c := 3, !Unsigned value = %000003
x := 271;
IF a '<' c THEN x := 314; !False; X still contains 271
IF a < c THEN x := 313; !True; X is assigned 313
IF a <> c THEN !True; this is an arithmetic
IF < THEN x := 314; ! comparison; since –2 < 3,
! CCL is set; x is assigned
! 314
IF a '<>' c THEN !True; this is a logical
IF > THEN x := 315; ! comparison; since
! %177776 '>' %3, CCG is set;
! X is assigned 315
Assigning Conditional
Expressions
You can assign the value of a conditional expression to a variable. The value assigned
is a –1 for the true state or a 0 for the false state.
For example, you can assign the result of a comparison to a variable:
INT neg := –1; !Value = %177777
INT pos := 1; !Value = %000001
INT result;
result := neg < pos; !Signed comparison produces –1
result := neg '<' pos; !Unsigned comparison produces 0
You can assign a –1 if either X or Y is a nonzero value (true), or a 0 if both X and Y are
zeros (false):
INT x, y, answer;
answer := x OR y; !Assign –1 or 0 to ANSWER