What are the building blocks of a program, and how do sequence, selection, iteration, procedures and recursion combine to express any algorithm?
Explain the principles of programming: data types, the three control structures, procedures and functions, parameter passing and recursion.
A focused answer to WJEC A-Level Computer Science Unit 1 principles of programming, covering data types and variables, sequence, selection and iteration, procedures, functions and parameter passing, and recursion.
Reviewed by: AI editorial process; not yet individually human-reviewed
Have a quick question? Jump to the Q&A page
Jump to a section
What this dot point is asking
WJEC wants you to explain the fundamental building blocks of a program: data types and variables, the three control structures, subroutines (procedures and functions), how parameters are passed, and recursion. These principles are language-independent and underpin Unit 2's practical programming. Expect questions that ask you to define and contrast terms (function versus procedure, by value versus by reference) and to trace a recursive routine by hand.
The answer
Data types and variables
Choosing the right type matters: storing a price as an integer would lose the pence, while a Boolean flag is more efficient and clearer than an integer 0 or 1.
The three control structures
Structured programming insists that these three suffice for any algorithm, which keeps code readable and avoids the tangled jumps of unstructured code.
Procedures, functions and parameters
A procedure carries out a task and returns no value through its name; a function returns a single value and is used within an expression. Both promote modularity: a problem is decomposed into reusable subroutines, each tested separately. Parameters pass data into a subroutine. By value passes a copy, so the original is unchanged; by reference passes the variable's location, so changes inside affect the original.
Recursion
Examples in context
- Example 1. Validating input with a condition-controlled loop
- A program that demands a password must keep asking until the entry is correct, which a REPEAT-UNTIL loop expresses directly: repeat the prompt until the condition is met. A count-controlled FOR loop would be wrong here because the number of attempts is not known in advance, illustrating why the type of loop must match the problem.
- Example 2. Decomposition with functions
- A payroll program might have a function grossPay() returning a value used in an expression, and a procedure printPayslip() that produces output but returns nothing. Splitting the task this way lets each part be tested on its own and reused, which is the whole point of modular subroutines.
- Example 3. When recursion is natural
- Walking a folder tree, where each folder may contain more folders, is naturally recursive: process this folder, then recurse into each subfolder. The base case is a folder with no subfolders. The structure of the data (a tree) mirrors the structure of the algorithm, which is why recursion suits tree and divide-and-conquer problems.
Try this
Q1. Name the three control structures used in structured programming. [3 marks]
- Cue. Sequence, selection and iteration.
Q2. State which type of loop is appropriate when the number of repetitions is known before the loop starts. [1 mark]
- Cue. A count-controlled loop (FOR).
Exam-style practice questions
Practice questions written in the style of WJEC exam questions on this dot point, with worked answer explainers. The year tag is the paper they imitate, not the source.
WJEC 20194 marksExplain the difference between a procedure and a function, and explain what is meant by passing a parameter by value as opposed to by reference.Show worked answer →
Define each subroutine type, then distinguish the two parameter-passing mechanisms.
A function returns a single value to the point where it was called and is typically used within an expression. A procedure carries out a task but does not return a value through its name; it may still change data through its parameters.
Passing by value copies the argument into the subroutine, so changes inside do not affect the original variable. Passing by reference passes the location of the variable, so changes inside the subroutine do affect the original.
Markers reward the return-value distinction between function and procedure, and the by-value (copy, original unchanged) versus by-reference (original can change) contrast.
WJEC 20214 marksA recursive routine is defined as factorial(n) = 1 if n = 0, otherwise n times factorial(n minus 1). State the base case, and trace the calls made to evaluate factorial(3).Show worked answer →
Identify the stopping condition, then expand the recursive calls until it is reached.
The base case is n = 0, which returns 1 and stops the recursion.
factorial(3) = 3 times factorial(2)
factorial(2) = 2 times factorial(1)
factorial(1) = 1 times factorial(0)
factorial(0) = 1 (base case)
Unwinding: factorial(1) = 1, factorial(2) = 2, factorial(3) = 6.
Markers reward identifying n = 0 as the base case, the chain of recursive calls down to the base case, and the unwound result of 6.
Related dot points
- Design algorithms in pseudocode, apply the standard searching and sorting algorithms, and compare algorithm efficiency.
A focused answer to WJEC A-Level Computer Science Unit 1 algorithms, covering algorithm design and pseudocode, linear and binary search, bubble, insertion and merge sort, and comparing efficiency.
- Describe and use arrays, records, lists, stacks, queues, trees and hash tables, and explain their operations and uses.
A focused answer to WJEC A-Level Computer Science Unit 1 data structures, covering arrays and records, the abstract data types stack and queue, lists, binary trees and hash tables, and when each is the right choice.
- Represent numbers in binary, hexadecimal and two's complement, perform binary arithmetic, and represent characters, sound and images as binary data.
A focused answer to WJEC A-Level Computer Science Unit 1 data representation, covering binary and hexadecimal, two's complement, binary arithmetic and shifts, and how characters, sound and images are stored as binary.
- Describe systems, application and utility software, the functions of the operating system, translators, and modes of operation.
A focused answer to WJEC A-Level Computer Science Unit 1 software and systems, covering system, application and utility software, operating system functions, compilers, interpreters and assemblers, and modes of operation.
- Use Boolean algebra, logic gates and truth tables to represent and simplify logical operations.
A focused answer to WJEC A-Level Computer Science Unit 1 logical operations, covering the logic gates and their truth tables, Boolean expressions and identities, and simplifying a logic circuit.