Programming fundamentals โ OCR GCSE Computer Science
Test yourself on Programming fundamentals with OCR GCSE practice questions.
7 days Premium ยท Then free forever ยท No card, no charge
Programming fundamentals explained
A program stores changing data in variables and fixed values in constants.
Read the full explanation
Each item should have a meaningful identifier and an appropriate data type. An assignment replaces the value held by a variable after evaluating the expression on its right. Input brings data into the program, often from a user or sensor, while output communicates a result through a screen, file or device. Operators combine or compare values to build expressions. Trace code in execution order, recording each assignment, because later statements can overwrite an earlier value.
The use of the three basic programming constructs used to control the flow of a program Sequence Selection Iteration (count- and condition-controlled loops)
Program flow is controlled by three constructs. Sequence executes statements one after another in written order, for example reading a sensor then storing its value then displaying it. Selection chooses between paths using a condition, such as IF score >= 50 THEN grade = "pass" ELSE grade = "fail". Iteration repeats code: count-controlled loops repeat a known number of times, for example FOR i = 1 TO 10, while condition-controlled loops repeat while or until a condition changes, for example WHILE answer != "yes" or REPEAT ... UNTIL valid. Combining constructs lets a programmer express any algorithm: a menu uses selection inside a condition-controlled loop, and processing a list uses a count-controlled loop containing selection. Choosing the right construct makes code readable, correct and efficient, and exam questions ask you to trace, write or correct code using them.
The common arithmetic operators
Arithmetic operators allow a program to perform mathematical calculations with numeric values. Addition, subtraction, multiplication and real division perform the familiar operations. Integer division (DIV) returns only the whole-number quotient, while modulus (MOD) returns the remainder. Exponentiation raises one value to a power. The exact symbols vary between languages, so exam questions often use OCR Reference Language. Apply standard precedence rules (BODMAS or BIDMAS): brackets first, then exponentiation, then division and multiplication, and finally addition and subtraction. Work through one operation at a time and track the data type of each result, noting that real division always produces a Real value.
The common Boolean operators AND, OR and NOT
Boolean operators work on truth values, each of which is either True or False. AND returns True only when both inputs are True, so True AND False is False. OR returns True when at least one input is True, so False OR True is True. NOT reverses a single value, so NOT True is False and NOT False is True. These operators let programs combine conditions, for example checking whether a user is logged in AND has admin rights, or whether a score is below zero OR above one hundred. In an exam, you may be asked to complete a truth table, evaluate an expression, or write a condition using AND, OR and NOT. Work through each operator in turn, applying brackets first, then NOT, then AND, then OR, and record the final truth value clearly.
Your focus
- Distinguish variables from constants in a short program.
- Trace assignments to determine the final values held by variables.
- Explain how inputs, operators and outputs form a simple processing sequence.
Show all 12 objectives
- Identify sequence, selection and iteration in a given program and explain the role of each.
- Choose an appropriate construct, including count-controlled or condition-controlled iteration, for a described task.
- Trace or write code that combines constructs, such as selection inside a loop, and predict its output.
- Evaluate arithmetic expressions using the stated precedence rules.
- Distinguish ordinary division, integer division and modulus.
- Select a suitable arithmetic operation for a programming task.
- State the result of applying AND, OR and NOT to given Boolean values.
- Evaluate a compound Boolean expression by applying brackets, NOT, AND and OR in the correct order.
- Construct a truth table for an expression that uses AND, OR and NOT.
Programming fundamentals exam tips
Marking Points
- Distinguish a variable, whose stored value can change, from a constant, whose value is fixed during execution. For example, score might be a variable, while VAT_RATE might be a constant.
- Explain that assignment evaluates an expression and stores the resulting value in the named variable. For example, total = price * quantity evaluates price * quantity and stores the result in total.
- Identify input as data entering a program and output as information produced by the program. For example, reading a user's name from the keyboard is input, while displaying a total on screen is output.
- Trace successive assignments in order and state the final value held by each relevant variable. For example, if x = 5 then x = x + 2, the final value of x is 7.
- Explain that operators combine or compare values to build expressions, such as using + to add two numbers or > to compare two values.
- Sequence: statements execute in the order written, so swapping two lines can change the result; tracing follows that order line by line.
- Selection: a condition is evaluated and exactly one branch runs, for example IF ... THEN ... ELSE ... or a CASE statement; the condition must be Boolean.
- Count-controlled iteration: the number of repetitions is known or calculated before the loop starts, for example FOR i = 1 TO 5 or a loop over a fixed list.
- Condition-controlled iteration: repetition continues while or until a condition is tested, for example WHILE lives > 0 or REPEAT ... UNTIL password = "secret".
- Nesting: constructs can be placed inside one another, so a selection can sit inside a loop and a loop can sit inside a selection.
- Tracing: track variable values after each iteration or branch to predict output and to find logic errors.
- Identify and apply addition, subtraction, multiplication and real division to numeric data types.
- Explain that integer division (DIV) produces the whole-number quotient, for example, 10 DIV 3 equals 3.
- Explain that modulus (MOD) produces the remainder of a division, for example, 10 MOD 3 equals 1.
- Apply brackets and the stated order of operations (BODMAS or BIDMAS) when evaluating a compound arithmetic expression.
- Calculate the result of exponentiation, which raises a base value to a stated power, distinguishing it from multiplication.
- State that real division produces a Real value, whereas integer division (DIV) produces an integer quotient.
- AND is a binary operator that produces True only when both of its operands are True; if either operand is False, the result is False. For example, True AND False evaluates to False.
- OR is a binary operator that produces True when at least one operand is True; it produces False only when both operands are False. For example, False OR True evaluates to True.
- NOT is a unary operator that negates a single Boolean value, turning True into False and False into True. For example, NOT False evaluates to True.
- Boolean expressions can be evaluated by substituting truth values and applying operator precedence, with brackets first, then NOT, then AND, then OR. For example, NOT True OR True is evaluated as (NOT True) OR True, giving False OR True, which is True.
- Boolean operators are used in selection and iteration to combine or invert conditions, such as while not finished or if age >= 18 and has_ticket.
- A truth table lists every combination of input values and the resulting output, which helps verify the behaviour of an expression. For two inputs, there are four rows: both False, first True, second True, and both True.
Examiner Tips
- ๐กUse a trace table with one column for each variable and update it after every assignment.
- ๐กWhen explaining a line of code, name the input, processing and resulting output separately.
- ๐กState both the data type and the purpose when asked to choose a suitable variable.
- ๐กRead the question's wording for clues: 'repeat until' or 'while' signals condition-controlled iteration, while 'for each' or a fixed number signals count-controlled iteration.
- ๐กWhen tracing, draw a table of variables and update it after every line or iteration so the final output is easy to justify.
- ๐กWhen writing code, indent nested constructs clearly; this helps you and the examiner see which statements belong to which branch or loop.
- ๐กCheck loop conditions by asking what value makes the loop stop and whether the body moves the variable towards that value.
- ๐กAnnotate the order in which operations will be evaluated above the expression before calculating the final result.
- ๐กFor integer division and modulus questions, write out the full division with a remainder (e.g., 13 divided by 5 is 2 remainder 3) before selecting the requested DIV or MOD value.
- ๐กWrite out each intermediate truth value when evaluating a compound expression, so your working can be followed and checked.
- ๐กUse brackets in written conditions to make the order of evaluation explicit, especially when NOT is combined with AND or OR.
- ๐กCheck a completed truth table by testing one row where all inputs are False and one row where all inputs are True, as these often reveal errors quickly.
Common Mistakes
- Treating assignment as a statement that two values are permanently equal. Correction: it stores a newly evaluated value in a variable. For example, x = x + 1 increases x by 1 rather than stating a mathematical equality.
- Calling every named value a variable. Correction: identify fixed named values as constants and changing named values as variables. For example, PI = 3.14 is a constant if it is not reassigned.
- Confusing input with output. Correction: describe the direction of data relative to the program. For example, a sensor reading entering the program is input, while a message sent to a screen is output.
- Confusing count-controlled and condition-controlled loops: a FOR loop is used when the number of repeats is known, while a WHILE loop is used when repetition depends on a condition; choose the construct that matches the problem.
- Writing a condition-controlled loop whose condition never becomes false, producing an infinite loop; ensure the loop body changes a variable used in the condition, for example incrementing a counter.
- Forgetting that an IF without ELSE simply skips its body when the condition is false, so no alternative action occurs; add ELSE when a different path is required.
- Using = instead of a comparison operator in a condition, or mixing up < and >, which changes which branch runs; check the operator against the intended meaning.
- Treating modulus (MOD) as ordinary division. Correction: modulus returns the remainder after integer division, so 7 MOD 2 is 1, not 3.5.
- Evaluating a compound expression strictly from left to right. Correction: apply standard operator precedence (BODMAS or BIDMAS) and evaluate brackets first.
- Confusing integer division (DIV) with real division. Correction: integer division truncates the decimal part, so 5 DIV 2 is 2, whereas real division of 5 by 2 is 2.5.
- Using the term 'float' instead of 'Real'. Correction: OCR J277 uses 'Real' for this data type, so use 'Real' in answers.
- Treating AND as if it returns True when either input is True; the correction is that AND requires both inputs to be True. For example, True AND False is False, not True.
- Confusing OR with exclusive or, expecting False when both inputs are True; the correction is that OR returns True when at least one input is True, including when both are True. For example, True OR True is True.
- Applying NOT to two values, as in NOT True AND False, without deciding which part is negated; the correction is that NOT applies to one value or a bracketed expression, so use brackets to make the intended meaning clear. For example, NOT (True AND False) is True, whereas (NOT True) AND False is False.