Relational operations in a programming language — AQA GCSE Computer Science
Verified courseTeaching note checked against the official specification.
Relational operations compare two values or expressions in a programming language and evaluate to a Boolean result of either True or False. In AQA GCSE Computer Science, mastering operators such as equal to (==), not equal to (!=), and comparison bounds (<, <=, >, >=) is essential for writing accurate selection and iteration constructs.
Relational operations in a programming language explained
Relational operators compare two values and return a Boolean result, which is then used to control program flow.
Read the full explanation
The core set is equal to, not equal to, less than, greater than, less than or equal to, and greater than or equal to. You must do two things: write them into your own programs, for example an if statement that checks whether a score is greater than or equal to a pass mark, and read them inside an algorithm written by someone else, working out what branch is taken for given inputs. Symbols vary between languages: some use a single equals sign for equality and others use a double equals sign, and not-equal may appear as a different symbol. Always check the language or pseudocode convention in the question before interpreting a comparison.
Your focus
- Evaluate a relational comparison in an algorithm for given input values and state the resulting branch.
- Write a correct relational comparison within a program to control selection.
- Distinguish equality from assignment and select the correct symbol for the stated language.
Which command word is this?
Give the specific relational operator or Boolean result without needing explanatory working or justification.
Relational operations in a programming language exam tips
Topic Overview
Relational operations are foundational programming constructs used to compare two values, expressions, or operands. They yield a Boolean outcome—evaluating strictly to either True or False—which allows computer programs to make decisions and control execution flow.
In AQA GCSE Computer Science, relational operators form the backbone of selection statements (IF-ELSE structures) and iteration constructs (WHILE and REPEAT loops). Understanding how each operator tests equivalence and order is vital for writing bug-free algorithms and interpreting trace tables.
Key Concepts
- →Relational operators compare two operands and always return a single Boolean value: True or False.
- →The standard relational set includes: Equal to (==), Not equal to (!= or ≠), Less than (<), Less than or equal to (<= or ≤), Greater than (>), and Greater than or equal to (>= or ≥).
- →Equality (==) tests whether expressions on both sides evaluate to the exact same value and type, distinct from variable assignment (=).
- →Relational operators have lower precedence than arithmetic operators (+, -, *, /) but higher precedence than Boolean logical operators (AND, OR, NOT).
Marking Points
- Identifies that a relational operator compares two values and produces a Boolean (true or false) result.
- Names the comparison operators: equal to, not equal to, less than, greater than, less than or equal to, greater than or equal to.
- Correctly traces an algorithm by evaluating a comparison for supplied input values and stating which branch runs.
- Writes a correct comparison in a program, for example testing a variable against a threshold inside a selection statement.
- Recognises that the symbol used for equality or inequality can differ between programming languages and checks the convention given.
Examiner Tips
- 💡Underline the comparison in a given algorithm, substitute the actual values, then state the true or false result before choosing the branch.
- 💡When writing code, match the operator symbol to the language or pseudocode convention printed in the question.
- 💡For multiple-choice items, eliminate options that confuse assignment with comparison or reverse the inequality direction.
- 💡Double-check boundary limits in problem descriptions; check whether words like 'between 1 and 10' are inclusive (>= 1 AND <= 10) or exclusive (> 1 AND < 10).
- 💡When tracing algorithms with WHILE loops, explicitly evaluate the relational condition at the start of each iteration in your rough working to avoid missing the loop termination point.
Common Mistakes
- Confusing assignment with comparison: a single equals sign may assign a value in some languages, so the learner must use the equality symbol the question's language requires.
- Reversing the direction of an inequality, so a test for greater than is read as less than; the correction is to substitute sample numbers and check the result.
- Treating a comparison as producing a number rather than a Boolean; the correction is to state that the outcome is true or false and drives selection.
- Believing '=' checks if two values are equal: A single equals sign assigns a value to a memory location, whereas double equals ('==') checks equality.
- Assuming string comparisons follow numerical logic: In most programming languages, strings are evaluated using lexicographical (ASCII/Unicode) order where uppercase letters have lower numerical values than lowercase letters.
- Confusing '<=' with '=<': Syntax requires the inequality symbol before the equals sign (<= or >=); writing '=<'' or '=>' causes a syntax error in languages like Python.
Revision Plan
- 1Day 1-2: Memorise all six relational operators and practice identifying the difference between assignment (=) and comparison (==).
- 2Day 3-5: Practice tracing selection (IF/ELIF/ELSE) code snippets involving relational boundary tests.
- 3Day 6-8: Solve exam-style algorithm design questions requiring relational comparisons within condition-controlled (WHILE) loops.
- 4Day 9-10: Review past AQA Paper 1 coding questions and complete self-marked timed tracing exercises.
Exam Question Types
- 📋Code Completion: Filling in the correct relational operator inside an IF or WHILE condition to satisfy a specification.
- 📋Trace Tables: Stepping through code line by line and evaluating relational expressions on each pass through a loop.
- 📋Algorithm Writing: Authoring high-level pseudocode or Python programs containing nested or compound relational conditions.
Command Word Expectations (AQA)
Give the specific relational operator or Boolean result without needing explanatory working or justification.
Work through given input data or a trace sequence to calculate the final Boolean outcome or output value.
Construct functional code or pseudocode using accurate relational syntax to fulfill specified algorithmic logic.
How Students Lose Marks (Examiner Pitfalls)
Step-by-Step Worked Solutions
Question: A cinema charges child fare for customers aged under 16, standard fare for customers aged 16 to 64 inclusive, and senior fare for customers aged 65 and over. Write an algorithm using pseudocode or Python that takes an integer input 'age' and outputs the correct ticket category.
- 1.Step 1: Receive the integer input representing age.
- 2.Step 2: Use the less than operator (<) to check if 'age < 16' and assign or output 'Child'.
- 3.Step 3: Use an ELSE IF / ELIF branch with the less than or equal to operator (<=) or logical operators to check if 'age <= 64' (since under 16 is already eliminated) and output 'Standard'.
- 4.Step 4: Use an ELSE branch to catch the remaining condition (age >= 65) and output 'Senior'.
Question: Evaluate the following Boolean expression when x = 12 and y = 15: (x * 2 > y + 5) AND (x != y)
- 1.Step 1: Evaluate arithmetic sub-expressions: x * 2 = 12 * 2 = 24; y + 5 = 15 + 5 = 20.
- 2.Step 2: Evaluate the first relational operation: 24 > 20, which evaluates to True.
- 3.Step 3: Evaluate the second relational operation: 12 != 15, which evaluates to True.
- 4.Step 4: Combine the Boolean results with AND: True AND True evaluates to True.