Relational Operators

The relational operators are = (is equal to), <> (is not equal to), > (is greater than), < (is less than), >= (is greater than or equal to) and <= (is less than or equal to).

All these have the same priority, which lower than any of the mathematical or Boolean operators. This explains why you need to put brackets round the expressions that need to be evaluated before a Boolean operation e.g. (Count <= MAX) and (Total <= 1000).

We have already given several examples of relational operators and you will see many more in other tutorials and in students' programs. When deciding which relational operator to use, you need to keep in mind the possibility of introducing an out-by-one error. We often see code such as
 if (Mark > 40) then Pass := True; 
where the pass mark is 40 and a student obtaining exactly 40 would feel justly aggrieved about being denied the pass. Make sure that you carry out boundary testing to catch any logic errors like this.
Programming - a skill for life!

Mathematical, Boolean and relational operators