Relational expressions

Arithmetical expressions may be compared with a set of operators (see the table above).
The comparison returns a boolean value: true or false. This boolean value may be assigned to a variable or used as the condition of a control structure, the "if" one for example.

Relational operators
=
<
<=
>
>=
<>
in
match
equal
less
less or equal
greater
greater or equal
not equal (the != C symbol is also valid)
member of a list
matches a user-defined function


Examples ot relational expressions: int x = 4
int
y= 5
boolean
b = x < 10
if y = 5 print "equal"

print x < y
print x = y
Displays (criptol C++): > equal
> true
> false


 Exercises

 

1) Four integer variables, a, b, c, d, are assigned the values 5, 10, 15, 20.
Two boolean variables are named x and y.
- x gets the value of the condition: a + c less ou equal to d.
- if x is true, y gets the value of the condition: d * 2 differs of 3,
else y evaluates to "false".

Display x and y with the print command.

Answer