Variables, constants and data types
A variable is a named store whose value can change while a program runs. A constant is a named value that stays the same. Common data types are integer (whole number), real (decimal), char (single character), string (text) and Boolean (TRUE or FALSE).
Program control structures
- Sequence — instructions run in order, one after another.
- Selection — a choice is made, using
IForCASE. - Iteration — a block repeats, using count-controlled (
FOR) or condition-controlled (WHILE,REPEAT) loops.
Example
Total ← 0
FOR i ← 1 TO 5
INPUT Mark
Total ← Total + Mark
NEXT i
Totalling and counting
Totalling keeps a running sum by adding each value to a total, as above. Counting keeps track of how many times something happens by adding one to a counter each time.
Remember
- A variable can change; a constant cannot.
- Totalling adds a value; counting adds one.
- A count-controlled loop repeats a set number of times.