Selection - AQA - GCSE Computer Science Revision - BBC Bitesize

In this guide

  1. Revise
  2. Video
  3. Test
  1. Data types
  2. The three basic programming concepts
  3. Variables and constants
  4. Count controlled iteration
  5. Condition controlled iteration
  6. Selection
  7. Subroutines
  8. Procedures and functions of subroutines
  9. Nested iteration and selection

Variables and constants

Programs usually use data in some shape or form. Data is often stored within a program using variables and constants.

Variables

A variable is a named piece of memory that holds a value. The value held in a variable can - and usually does - change as the program is running.

A variable's name is known as an identifier. The identifier given to a variable usually follows certain rules known as a naming convention:

  • It can contain letters and numbers but must start with a letter.
  • It must contain at least one letter - at the start of the name.
  • It must not contain special characters such as !@£$%&* or punctuation characters. However, an underscore can be used. Spaces are not allowed.
  • It should contain lowercase letters. However, uppercase letters can be used if a variable name comprises more than one word joined together.
  • The name should be meaningful - it should represent the value it is holding.
Acceptable identifiersUnacceptable identifiers
highScorehigh score
high_score123score
highScore123$core
Acceptable identifiershighScore
Unacceptable identifiershigh score
Acceptable identifiershigh_score
Unacceptable identifiers123score
Acceptable identifiershighScore123
Unacceptable identifiers$core

Variables make it easy for a programmer to use memory locations. The computer keeps track of which memory location the variable refers to. All the programmer has to do is remember the identifier the variable was given.

Structured programming

Structured programming can also be referred to as modular programming. It involves breaking down a program into manageable chunks to perform individual tasks. The individual tasks can be written as subroutines and combined to create a main program. With this programming, it is important to document the interface of each module including the module name, local variables, processes, parameters, and return values.

Advantages of structured programming

  • Programming is much easier as each subroutine performs a simple task.
  • Many programmers can work on one program as the modules can be written independently.
  • It is easier to test as each subroutine can be tested and fixed independently.
  • Subroutines can be reused in future programs.

Declaration and assignment

Most programming languages require a variable to be identified before a value is assigned to it. This is known as declaring a variable. In Visual Basic, this would look like:

Dim score as Integer - would declare a variable called score which will hold integers.

Giving a variable a value is known as assignment. For example, giving the variable above a value would look like the following in Visual Basic:

score = 0 - would assign the value 0 to the variable score

Some programming languages, such as Python, do not require variables to be explicitly declared before use.

Constants

A constant is a named piece of memory where the value cannot be changed while a program runs.

Constants are useful because they are declared and assigned once, but can be referred to over and over again throughout the program. This means that if the programmer needs to change the value throughout the program code, they only need to make one change. This can help make a program easier to maintain.

Constants follow the same naming conventions as variables, except that they are often written in uppercase. Some programming languages, such as Python, do not support constants.

Constants are used for values that are unlikely to change, for example:

Pi - PI ← 3.142

Global and local variables

A global variable is one that can be accessed and changed throughout the whole program. Local variables only exist within a particular subroutine.

Using local variables rather than global variables makes it easier to debug a program as the value of that variable can only be read or changed within one subroutine. Another advantage of local variables is memory efficiency. Once a subroutine has finished running, the memory used for all local variables is removed.

In general, the use of global variables should be avoided wherever possible.

Next pageCount controlled iterationPrevious pageThe three basic programming concepts

More guides on this topic

  • Fundamentals of algorithms - AQA
  • Searching and sorting algorithms - AQA
  • Programming languages - AQA
  • Further programming language operations - AQA
  • Fundamentals of data representation - AQA

Related links

  • Computer Science exam practice
  • Computer Science revision
  • Personalise your Bitesize!
  • Jobs that use Computer Science
  • BBC News: Technology
  • Raspberry Pi
  • Quizlet
  • micro:bit
  • Code
  • Learn Python Subscription

Tag » What Is Selection In Computer Science