GCSE Computer Science · Computational thinking, algorithms and programming

Programming fundamentals

Variables, constants and data types, input and output, the operators, and sequence, selection and iteration.

338 GCSE-style practice questions

Watch the lesson

Every point below, worked through in one video, and each point links straight to its own part.

9 minutes. Plays from YouTube.

More lessons like this one on our YouTube channel

Learn

Programming fundamentals, explained point by point

Everything the GCSE specification expects you to be able to do, and how to actually do it - the same lesson a signed-in student studies from.

  1. Read code in the notation your exam uses

    The ideas in this topic are the same on every board, but the paper prints them differently. OCR shows code in its Exam Reference Language, and in the last section of Paper 2 you may answer in that or in a high-level language such as Python. AQA’s Paper 1 comes in three versions, C#, Python and VB.NET, and your school enters you for one. Edexcel’s Paper 2 and Eduqas’s Component 2 are sat at a computer in Python 3. Find out which applies to you, and practise reading and writing code in it.

  2. Use variables, constants, assignment, input and output

    A variable is a named place in memory whose value can change while the program runs. A constant is named in the same way, but its value is set once and cannot change, which suits a value such as a VAT rate. Assignment gives a variable a value. Input brings data in from the user and output displays a result. Give every variable a name that says what it holds: total is better than t.

  3. Choose the right data type, and convert between types

    An integer is a whole number. A real number, which Python calls a float and C# and VB.NET call a double, has a decimal part. A Boolean is either true or false. A character is a single letter, digit or symbol, and a string is a sequence of characters. Choose the type that fits the data: a phone number is a string, because it can start with 0 and is never used in a sum. Casting converts a value from one type to another, such as turning the string typed by a user into an integer before adding it.

  4. Use the arithmetic operators, including integer division and remainder

    As well as add, subtract, multiply and divide, there are two operators that only programmers use. Integer division gives the whole-number part of a division, so 17 integer-divided by 5 is 3. The remainder operator, often called modulus, gives what is left over, so the remainder of 17 divided by 5 is 2. OCR and AQA write these as DIV and MOD. Python uses two slashes and a percent sign. In C#, a single slash between two integers already gives the whole-number part, and the remainder is a percent sign; VB.NET uses a backslash and Mod, and its single slash always keeps the decimal part. A remainder of 0 after dividing by 2 is the usual test for an even number. OCR and Edexcel also examine an operator for powers.

  5. Use comparison operators and the Boolean operators AND, OR and NOT

    A comparison gives a Boolean result, true or false. There are six: equal to, not equal to, less than, less than or equal to, greater than, and greater than or equal to. Most languages write equal to as a double equals sign, because a single one means assignment. Join conditions with AND when both must be true and with OR when either will do. NOT reverses a condition. A common use is checking a range: a mark is valid if it is at least 0 AND at most 100.

  6. Use sequence and selection

    Sequence means the instructions are carried out in the order they are written, one after another. Selection means the program chooses which instructions to run, depending on a condition. The usual form is an if statement, with else for what to do otherwise, and extra conditions in between when there are more than two cases. Only one branch ever runs. Selections can be nested, one inside another, when a second decision only matters after the first.

  7. Use iteration: count-controlled and condition-controlled loops

    Iteration means repeating instructions. A count-controlled loop, a for loop, repeats a set number of times and is right when you know how many repeats are needed. A condition-controlled loop, a while loop, repeats for as long as a condition is true and is right when you do not know in advance, such as asking for a password until it is correct. Some languages can also test the condition at the end, so that the loop always runs at least once. Edexcel adds a third pattern: stepping through every item of a list or string in turn.

Programming fundamentals key terms

The words the specification and the mark schemes use, each defined the way an examiner wants it.

Variable
A named location in memory that holds a value which can change while the program runs.
Constant
A named value that is set once and cannot change while the program runs.
Assignment
Giving a value to a variable or a constant.
Data type
The kind of value a variable holds, such as integer, real, Boolean, character or string.
Casting
Converting a value from one data type to another.
Sequence
Carrying out instructions one after another in the order they are written.
Selection
Choosing which instructions to carry out according to whether a condition is true.
Iteration
Repeating a group of instructions, either a set number of times or while a condition holds.
Integer division
Division that gives only the whole-number part of the result, written DIV in some languages.
Modulus
The operation that gives the remainder after one whole number is divided by another, written MOD in some languages.
Boolean
A data type that has only two possible values, true and false.

Common mistakes in Programming fundamentals

The slips that cost marks year after year, and what to do instead.

  • Mixing up integer division and remainder

    Integer division gives how many whole times one number goes into another. The remainder is what is left over afterwards.

  • Using a single equals sign to compare two values

    In most languages one equals sign assigns a value and two compare. Check which your exam’s notation uses.

  • Adding a number that was typed in before converting it

    Input usually arrives as a string. Cast it to an integer or a real number before doing any arithmetic with it.

  • Choosing a for loop when the number of repeats is not known

    Use a condition-controlled loop when the program must repeat until something happens, such as a correct password.

  • Being one out on where a loop starts or stops

    Trace the first and the last time round the loop, and check whether the end value is included.

Practice

Try a Programming fundamentals question

A GCSE-style original question from this topic. Have a go before you open the working - deciding on an answer first is what makes the working stick.

In Python, what is the value of 7 + 3 * 2?

Make Programming fundamentals stick

A free account adds worked examples from our question bank, from a warm-up to a stretch, plus ask-Wiz - a coach you can put any point from this lesson to - and a checklist that remembers which points you've studied. No card needed.

Ready to practise Programming fundamentals?

Sign up free to practise this topic - questions that adapt to how you're doing, with instant encouraging feedback on every answer. No card needed.

Download on the App StoreGet it on Google Play

Already have an account? Log in

More Computational thinking, algorithms and programming topics