Selection - AQA - GCSE Computer Science Revision - BBC Bitesize
Maybe your like
In this guide
- Revise
- Video
- Test
Pages
- Data types
- The three basic programming concepts
- Variables and constants
- Count controlled iteration
- Condition controlled iteration
- Selection
- Subroutines
- Procedures and functions of subroutines
- Nested iteration and selection
Variables and constants
ProgramscloseSequences of instructions for a computer. usually use datacloseUnits of information. In computing there can be different data types, including integers, characters and Boolean. Data is often acted on by instructions. in some shape or form. Data is often stored within a program using variables and constants.
Variables
A variablecloseA memory location within a computer program where values are stored. 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 identifiers | Unacceptable identifiers |
| highScore | high score |
| high_score | 123score |
| highScore123 | $core |
| Acceptable identifiers | highScore |
|---|---|
| Unacceptable identifiers | high score |
| Acceptable identifiers | high_score |
|---|---|
| Unacceptable identifiers | 123score |
| Acceptable identifiers | highScore123 |
|---|---|
| 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 variablescloseA memory location within a computer program where values are stored., 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 languagescloseA language used by a programmer to write a piece of software. 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 conceptsMore 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
-
Selection In Programming - KS3 Computer Science Revision - BBC
-
Selection - Computer Science GCSE GURU
-
Selection In Programming | Types & Importance
-
[PDF] Selection In Programming
-
What Is Selection In Programming? - Quora
-
Selection - Isaac Computer Science
-
What Is Selection In Programming? - FutureLearn
-
What Is Selection? - Webopedia
-
Selection - Bits Of
-
Selection Strategy - Computer Science Wiki
-
Computer Science: Sequences, Selections, And Loops - GCFGlobal
-
5 Minutes To Code: Programming Basics "Selection" - YouTube
-
Selection Algorithm - Wikipedia