CS Notes
CS Notes
Programming involves writing a set of instructions to solve problems or perform tasks using a
computer. At the IGCSE level, the emphasis is on understanding the logic behind code,
constructing algorithms using pseudocode or Python-like syntax, and tracing through algorithms
to predict outcomes.
A program is made up of variables, data structures (like arrays), control structures (such as
loops and decisions), and possibly functions or procedures (if included in your syllabus). Each
part plays a critical role in the logical flow of the program.
Variables are named storage locations that hold data which can change during the execution of
a program. Every variable has a data type that defines what kind of data it can hold. For
example, INTEGER stores whole numbers, REAL stores decimal numbers, STRING stores
sequences of characters, CHAR holds a single character, and BOOLEAN represents values that
are either TRUE or FALSE.
Constants, unlike variables, store values that do not change throughout the program. They are
useful for values like π or a tax rate that stay fixed.
It is important to declare variables properly and use meaningful names that indicate their
purpose. This improves readability and helps reduce errors during testing and debugging.
Input allows a program to take data from the user using commands like INPUT. Output is used
to display information, typically with OUTPUT or PRINT. Assignment (←) is used to set a
variable’s value. For example, total ← num1 + num2 assigns the sum of two variables to
another variable. Assignment statements are crucial because they allow the program to perform
calculations, store results, and update data during runtime.
Selection (IF...THEN...ELSE)
Selection is a way for a program to make decisions. Using IF statements, a program can
choose between different paths based on conditions. For example:
Nested IF statements or ELSEIF branches are used when there are multiple conditions to
evaluate. Logical operators like AND, OR, and NOT are often used to form compound conditions.
Iteration (Loops)
Iteration is the repetition of a block of code. There are two main types of loops: count-controlled
and condition-controlled.
FOR i ← 1 TO 10
OUTPUT i
NEXT i
This loop prints numbers from 1 to 10. The loop variable i automatically increases with each
repetition.
A WHILE loop runs as long as a condition remains true. It is used when the number of
repetitions is unknown. For example:
This loop continues asking for input until the user enters the correct password.
Inside loops, programmers can perform calculations, check conditions, and process data from
arrays or input. Understanding loop flow is essential for writing efficient algorithms.
Arrays (One-Dimensional)
An array is a data structure that holds multiple values of the same data type under one name.
Each value is stored at a specific position called an index. Indexing usually starts at 0 or 1
depending on the language.
For example, the array names[1..5] can store five string values. You can access the third
name using names[3], update it with names[3] ← "Ali", or use a loop to read all names.
Arrays are commonly used to store lists like marks, prices, or usernames. Loops are used to
input data into arrays, search for specific values, calculate averages, or find maximum/minimum
elements.
Understanding how to manipulate arrays with loops is essential, especially in exam tasks
involving processing student scores or handling lists of items.
Trace Tables
Trace tables are used to simulate how variables change as a program runs. Each row
represents a step or line of code, and each column tracks the value of a variable. They are
essential for debugging, especially for loops and conditionals. Cambridge loves trace table
questions because they test a student's understanding of how code executes line by line.
To complete a trace table, write down the initial values of all variables, and update them as each
line of the pseudocode is "executed" in your mind. Carefully track the values, especially in loops
and conditional branches.
You are expected to write pseudocode that solves real-world problems. This includes tasks like
calculating averages, validating passwords, searching through a list, or printing specific values.
Your pseudocode should follow correct syntax and structure, using appropriate variables,
indentation, and logic.
Good pseudocode is clear, logical, and easy to follow. It should have proper variable naming,
use loops and conditions where needed, and handle input/output correctly. Comments are not
usually required unless explicitly asked, but showing clear structure helps with marks.
sum ← 0
FOR i ← 1 TO 5
INPUT num
sum ← sum + num
NEXT i
average ← sum / 5
OUTPUT average
This example demonstrates the use of a variable (sum), a FOR loop, and arithmetic operations to
solve a common problem.
Final Advice
Don't try to memorize long solutions—instead, understand how each structure works and how to
combine them. Practise mentally running through code, imagining how variables change. If you
can do that, you’ll be well-prepared for whatever the paper throws at you.