You are on page 1of 7

A-Level Computer Science

Program Flow
Introduction
Programming languages have a set of statements to determine how to reach a goal. The FLOW of these
statements is CONTROLLED by 3 different structures:

Sequencing
(Performing one instruction after another)

Selection
(The program making decisions)

Iteration
(The program repeating, looping infinitely or for a set number of
times)

Sequencing
A sequence is a control structure where the computer executes every instruction in the order in which they
are written. Here is an example of sequencing in an algorithm:

Each line is executed before moving on to the next.

Selection – Conditional Operations

Computer Science UK Membership Site Licence: Do not share outside your centre. 1
A-Level Computer Science

Often we want programs to act differently when certain conditions occur. Selection is a control structure
which contains instructions that DO NOT have to be executed in sequence (non-sequential).
There are two main types of selection.
 Selection of 2 possible pathways (IF-THEN-ELSE statements)
 Multiple Selections (CASE statements (uses the keyword ELIF in Python))

Selection of 2 – IF-THEN-ELSE STATEMENTS


These are used to see if a certain condition is true or false. IF the
condition is true THEN a certain set of instructions will be
executed. ELSE (condition is false) then a different set of
instructions will be executed.

Multiple Selection – CASE STATEMENTS (ELIF in Python)


These are used to run one of many possible instructions based on various conditions. It makes use of CASE
OF and ENDCASE to select one
instruction from a set of instructions,
depending on the value of a variable. It
does the same job as multiple (nested) IF-
ELSE statements but is more efficient.

Iterations – Iterative Operations


Often we want programs to repeat a process until a condition is met. Iteration is the Control Structure which
allows this to occur.
There are two ways to get code to loop:
1. Counting a set number of loops
2. Setting a condition which must be met for the loop to end.
Counting a set number of loops
If we know how many times we want a loop to run for we use a FOR
loop. This uses a counter with FOR, TO and NEXT to repeat a block
of code a set number of times. The counter can go up or down in
different steps.

Setting a condition (which must be met to enter a loop)


If we do not know how many times we want a loop to run
for and instead want the loop to repeat until a certain
condition is met we will use a WHILE loop.

Computer Science UK Membership Site Licence: Do not share outside your centre. 2
A-Level Computer Science

This states that WHILE a certain condition is true, the code will continue repeating. The check occurs at the
start of each loop. The instructions in the loop will be ignored if the WHILE condition is false.

Setting a condition (which must be met for the loop to end)


In most programming languages (but not python) there is also a REPEAT
UNTIL loop which will repeat a block of code until a condition occurs.
The check is always carried out at the end of the loop. Unlike the WHILE loop,
the instructions will always be carried out at least once.

Questions
1. Name the 3 constructs of a programming language? [3]
2. Describe how each of the three constructs above control the flow of instructions in a program? [3]
3. Copy the code shown at the bottom of the page and identify (by labelling) the various parts of the
code where the three programming constructs have been used. [3]
4. Explain the difference between how FOR loops and WHILE loops control the flow of instructions
during the running of a program. [4]
5. Explain how iteration controls the flow of instructions in a program and explain the difference
between how a ‘while loop’ and a ‘do until’ structure controls the flow of instructions. [4]
6. Although IF statements allow for only 2 possible pathways, IF statements can be nested within
themselves to allow for multiple pathways. Describe another method that can be used to enable the
programming of multiple possible pathways.
Computer Science UK Membership Site Licence: Do not share outside your centre. 3
A-Level Computer Science

7. Write a short program which makes use of all three programming constructs.[5]

_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
Computer Science UK Membership Site Licence: Do not share outside your centre.
4
_____________________________________________________
A-Level Computer Science

Keywords / Key Terms:


Checklist: Sequencing: A control structure where the computer executes every instruction in
 Date and title, clearly presented the order in which they are written.
 Spelling & grammar checked Selection: A control structure which contains instructions that DO NOT have to be
 Question numbers in the margin executed in sequence (non-sequential). The executed instruction is selected based
 Handwriting neat & legible on a condition at that time.
Iteration: A control structure which allows instruction to be repeated, either for a
 Punctuation / Capital letters set number of times or based on the result of a condition.

_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
Computer Science UK Membership Site Licence: Do not share outside your centre.
5
A-Level Computer Science

 State/Identify/Give/Name: Simply label a diagram, fill out a table or write a few words
 Describe: Describing is ‘saying what you see’ (E.G.: A computer will have a CPU, Primary and Secondary storage etc)
 Explain: Explaining is ‘saying WHY/HOW something is like that’. (E.G.: A computer will have a CPU so that it can process all of the data the
computer needs to perform a range of tasks. Primary and Secondary storage is needed because…)
 Discuss: Discussing is ‘looking at two sides of an issue, weighing up the two views and giving a conclusion’. Often these require a mini essay
answer. (E.G.: New technology could be seen as being bad for the environment because…, but on the other hand, new technology has led to…
In conclusion I believe that…)
 Describe/Explain/Discuss using examples: Finally, if you are asked to give examples in any of these types of questions – YOU MUST GIVE
EXAMPLES!

Stick answer sheet here

Computer Science UK Membership Site Licence: Do not share outside your centre. 6
A-Level Computer Science

Reflections: Score: / Percentage: % Grade: Progress: On / Above / Below

What Went Well?:  My answers effectively incorporated technical terminology.


 I demonstrated a good level of understanding.  My responses were well structured / organised.
 I responded to the command words effectively.  My revision strategy was effective as I showed depth of understanding in my
answers.
 My answers were detailed / were written in depth.
 My answers contained enough points / examples / explanations to achieve the
 My work was well presented / legible.
marks available.

Even Better If…:  I must incorporate key terminology into my answers.


 I must better organise my answers to improve its clarity.
 My answers need to be more accurate.
 I need to improve my revision strategy, as I did not demonstrate a depth of
 I must respond correctly to the command words. understanding in my answers.
 My answers need more detail / greater depth.  My answers didn’t contain enough points / examples / explanations to
 I must take greater care over my work / write neatly. achieve the marks available.

Further thoughts:
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________

Computer Science UK Membership Site Licence: Do not share outside your centre. 7

You might also like