Skip to topic
    ← Back to course topics

    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.

    Read the Relational operations in a programming language study guideFull revision notes for AQA GCSE Computer Science

    Your focus

    1. Evaluate a relational comparison in an algorithm for given input values and state the resulting branch.
    2. Write a correct relational comparison within a program to control selection.
    3. 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
    1. 1Day 1-2: Memorise all six relational operators and practice identifying the difference between assignment (=) and comparison (==).
    2. 2Day 3-5: Practice tracing selection (IF/ELIF/ELSE) code snippets involving relational boundary tests.
    3. 3Day 6-8: Solve exam-style algorithm design questions requiring relational comparisons within condition-controlled (WHILE) loops.
    4. 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)
    State

    Give the specific relational operator or Boolean result without needing explanatory working or justification.

    Determine

    Work through given input data or a trace sequence to calculate the final Boolean outcome or output value.

    Write

    Construct functional code or pseudocode using accurate relational syntax to fulfill specified algorithmic logic.

    How Students Lose Marks (Examiner Pitfalls)
    Pitfall: Confusing the assignment operator (=) with the equality comparison operator (==) in condition statements.
    ❌ Weak Answer (Loses Marks):IF score = 100 THEN OUTPUT 'Full marks'
    Example improved answer:IF score == 100 THEN OUTPUT 'Full marks' (or 'IF score = 100' only if explicitly using pseudocode that allows single equals, but standard high-level languages like Python and AQA pseudocode specification demand distinguishing assignment from equality test '==').
    Examiner Tip: Always inspect whether a variable is receiving a new value (assignment) or being tested against another value (equality). In Paper 1 coding questions, writing '=' instead of '==' inside an IF condition is one of the most frequent syntax errors penalised by examiners.
    Pitfall: Mixing up strict inequalities (<, >) with inclusive inequalities (<=, >=), leading to off-by-one boundary errors.
    ❌ Weak Answer (Loses Marks):IF age > 18 THEN OUTPUT 'Eligible to vote'
    Example improved answer:IF age >= 18 THEN OUTPUT 'Eligible to vote'
    Examiner Tip: Carefully read whether boundary values are included. Phrases such as 'at least 18' or '18 and above' require the greater than or equal to operator (>=), whereas 'strictly greater than 18' requires (>).
    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. 1.Step 1: Receive the integer input representing age.
    2. 2.Step 2: Use the less than operator (<) to check if 'age < 16' and assign or output 'Child'.
    3. 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. 4.Step 4: Use an ELSE branch to catch the remaining condition (age >= 65) and output 'Senior'.
    Final Answer: age = int(input('Enter age: ')) if age < 16: print('Child') elif age <= 64: print('Standard') else: print('Senior')

    Question: Evaluate the following Boolean expression when x = 12 and y = 15: (x * 2 > y + 5) AND (x != y)

    1. 1.Step 1: Evaluate arithmetic sub-expressions: x * 2 = 12 * 2 = 24; y + 5 = 15 + 5 = 20.
    2. 2.Step 2: Evaluate the first relational operation: 24 > 20, which evaluates to True.
    3. 3.Step 3: Evaluate the second relational operation: 12 != 15, which evaluates to True.
    4. 4.Step 4: Combine the Boolean results with AND: True AND True evaluates to True.
    Final Answer: True
    Active Recall Memory Test
    What data type is always produced as the output of a relational operation?
    Key Fact: A Boolean value (True or False).
    Which relational operator tests whether two values are NOT equal in Python and AQA pseudocode?
    Key Fact: != (or ≠ in standard pseudocode representations).
    What is the difference in functionality between 'x = 5' and 'x == 5'?
    Key Fact: 'x = 5' assigns the integer value 5 to variable x, while 'x == 5' compares the value stored in x to 5 and returns True or False.
    If score = 50, what does the expression 'score <= 50' evaluate to?
    Key Fact: True, because 50 is less than or equal to 50.
    Frequently Asked Questions
    Why do programming languages use == instead of = for comparison?
    Programming languages use '=' as the assignment operator to store a value in a variable. Because computers need distinct instructions for assigning values versus testing equality, designers introduced '==' to perform comparison. Using different symbols prevents ambiguity in the compiler or interpreter.
    Can I compare two different data types using relational operators?
    It depends on the language and the operator. In Python, comparing a string and an integer with equality (e.g., '5' == 5) returns False without an error. However, using ordering operators like < or > between incompatible types (e.g., '5' > 3) raises a TypeError, meaning you must cast types before comparing.
    How do relational operators work with text strings?
    When comparing strings, relational operators compare the ASCII or Unicode character values from left to right. For instance, 'apple' < 'banana' evaluates to True because 'a' (ASCII 97) is less than 'b' (ASCII 98). Be aware that uppercase letters have lower numerical codes than lowercase letters, so 'Z' < 'a' evaluates to True.
    What is the order of precedence between arithmetic, relational, and Boolean operators?
    Arithmetic operations (+, -, *, /) have the highest precedence and are calculated first. Relational operators (<, <=, >, >=, ==, !=) are evaluated next. Finally, logical Boolean operators (NOT, AND, OR) have the lowest precedence, allowing expressions like 'x + 2 > 10 AND y == 4' to work correctly without mandatory extra parentheses.
    Does AQA penalise writing = instead of == in Paper 1?
    In pseudocode answers, examiners may occasionally tolerate '=' for equality if the intent is unmistakable, but in language-specific questions (such as Python or C#), using '=' inside an IF statement is treated as a syntax or semantic error and loses marks. It is best practice to consistently write '==' for comparison.