Session XP: 0
Topic 1AComponent 1

Programming Concepts

Variables, constants, data types, sequence, selection, iteration, subprograms. Pseudocode questions and trace tables require these.

Best score
Last attempt
Best attempt progress
0
XP earned
Watch first — Craig 'n' Dave
Craig 'n' Dave · Edexcel 1CP2Programming Constructs
Key facts

Core constructs

  • Sequence — statements executed in order, one after another.
  • Selection — IF/ELSE statements that choose different paths based on a condition.
  • Iteration — loops. FOR loops (fixed number of times). WHILE loops (condition-controlled). REPEAT/UNTIL loops.
  • Variables — named memory locations whose value can change during program execution.
  • Constants — named memory locations whose value is set once and cannot change. Written in CAPITALS by convention.
  • Jun 2023 Specimen Q5(c): constants — "if the value does have to be altered, only one change is required".

Advantages of constants

  • Less likely to be accidentally changed → more robust programs
  • If the value needs updating, only ONE change needed (where the constant is defined)
  • Makes code easier to read — a meaningful name is more readable than a "magic number"
  • Example: MAX_SPEED = 70 is clearer than using 70 throughout the code

Input validation and error types

Exam questions — 4 questions · 12 marks · from real 1CP2 past papers
1 markSyntax error1CP2 Jun 2024 Q1(d)(i) style

What is a syntax error?

A A program that runs but produces the wrong answer
B A program that crashes when dividing by zero
C Code that violates the grammar or rules of the programming language
D A variable that contains the wrong data type
1 markConstant vs variable1CP2 Specimen Q5(c) style

Why should a programmer use a constant instead of a variable to store the value of pi (3.14159)?

A Constants are stored faster by the CPU
B Constants use less memory than variables
C Pi should never change during the program — using a constant prevents accidental modification and if the value ever needs updating, only one change is required
D Variables cannot store decimal numbers
4 marksDescribe iteration types1CP2 style

Describe the difference between a FOR loop and a WHILE loop. Give an example situation where each would be most appropriate. (4 marks)

Hint: Cover: how each loop is controlled (count vs condition) + when each is appropriate. Two marks per loop type.
+40 XP
4 marksError type identification1CP2 Jun 2024 Q1(d)(ii) style

A program contains the following code: result = 10 / userInput Explain what type of error occurs if the user enters 0, and why the program behaves as it does. (2 marks — linked)

Hint: Name the error type (runtime) AND explain WHY — what makes this impossible for the CPU to execute.
+40 XP

Module complete! 🎉

Score loading...

+10 XP