Programming foundations are the small building blocks every program uses: variables, data types, decisions, loops and functions. Once you can predict what each block does, larger programs are just these blocks arranged in order.
This section sits inside the SPM Computer Science subject hub. It pairs naturally with problem solving and algorithms, which covers planning before you code.
How do the parts connect?
Each idea depends on the previous one.
- Variables and data types store values and decide which operations are allowed.
- Selection uses those values in a condition to choose one path.
- Loops repeat a path while a condition holds, so the boundaries must be exact.
- Functions wrap a set of steps with a name, taking values in and sending one back.
A fault in an early block travels upward. A wrongly typed variable can make a condition false, and that in turn makes a loop stop at the wrong place.
A small program that uses every idea
CONSTANT PASS_MARK = 40
FUNCTION result(mark)
IF mark >= PASS_MARK THEN
RETURN "Pass"
ELSE
RETURN "Fail"
END IF
END FUNCTION
FOR i = 1 TO 3
INPUT score
OUTPUT result(score)
NEXT i
Enter 52, 40 and 39. The outputs are Pass, Pass and Fail. Here the constant never changes, the variable score changes on each pass, the IF chooses a path, the loop runs three times, and the function returns one answer.
If score had been stored as text, the comparison with 40 would be unreliable. That is why the first lesson is about types.
Where should you start?
Choose the row that matches your symptom.
| Symptom | Start with |
|---|---|
| Unsure what to store a value as | Variables, constants and data types |
| A loop runs one time too many or too few | Writing loops with correct boundaries |
| Lost inside a function call | Tracing functions and parameters |
| Program runs but behaves strangely | Program structure and debugging |
Test the whole set with the programming foundations practice questions. The restricted pseudocode trace trainer gives extra tracing drills on your own device.
If you would like a teacher to build programs with you from the blank page, see online one-to-one Computer Science tuition.