Programming Concepts
Programming
Comparison operators compare two values and return a (TRUE or FALSE). They are the building blocks of IF statements and loop conditions.
| Operator | Meaning | Example | Result |
|---|---|---|---|
= | Equal to | Age = 18 | TRUE if age is 18 |
<> | Not equal to | Score <> 0 | TRUE if score is not zero |
< | Less than | Speed < 30 | TRUE if speed under 30 |
> | Greater than | Temperature > 25 | TRUE if temperature over 25 |
<= | Less than or equal to | Mark <= 40 | TRUE if mark is 40 or below |
>= | Greater than or equal to | Age >= 18 | TRUE if age is at least 18 |
Common slip: in some real programming languages (Python, Java), the test for equality is
==, not=. In CIE pseudocode the single=is correct, so use it in pseudocode answers.
Common exam question
Identifying operators and their types
Question: Tick the operator that means less than or equal to, or draw lines from operators such as >=, AND, DIV and + to the operator types arithmetic, logical and Boolean (1–4 marks).
Asked in 2 of the 17 papers, one mark per correct tick or line. Know the symbols: <= is less than or equal to, >= greater than or equal to and <> not equal to; the wrong options offered were OR, < and >=.
Sort operators by what they do, because the group names have changed. +, -, *, /, ^, DIV and MOD calculate a number: arithmetic. =, <, <=, >, >= and <> compare two values: relational in the current syllabus, labelled "logical" on earlier papers. AND, OR and NOT combine TRUE and FALSE values: logical now, labelled "Boolean" on earlier papers. So with the labels Boolean, arithmetic and logical on offer, >= goes to logical, AND to Boolean, and DIV and + to arithmetic.