Programming concepts — data and control structures
Introduced| English | Meaning |
|---|---|
| variable/ˈveərɪəbl/ | A quantity or named value that can change or take different values. |
| constant/ˈkɒnstənt/ | A named or literal value that does not change during the relevant part of a program. |
| data type/ˈdeɪtə taɪp/ | A classification of values that determines their representation and permitted operations. |
| integer/ˈɪntɪdʒə/ | A whole number that may be positive, negative or zero. |
| real/rɪəl/ | A numeric data type used to represent numbers with fractional parts, generally with limited precision. |
| string/strɪŋ/ | A sequence of characters treated as a single data value. |
| Boolean/ˈbuːlɪən/ | A logical value that is either true or false. |
| sequence/ˈsiːkwəns/ | The order in which items appear or operations are carried out. |
| selection/sɪˈlekʃn/ | Choosing which branch of instructions to execute according to a condition. |
| iteration/ˌɪtəˈreɪʃn/ | Repeating a sequence of instructions or calculations. |
Programming building blocks
- Programs store data in variables 变量 and constants 常量, each with a data type 数据类型.
- They are built from three control structures.
- We finish with the totalling and counting patterns.
Variables, constants and data types
- A variable can change; a constant is fixed. Declare both before use.
- Five basic data types: integer 整数 (whole number), real 实数 (decimal), char (one character), string 字符串 (text), Boolean 布尔值 (
TRUE/FALSE).
DECLARE Score : INTEGER
CONSTANT Pi ← 3.142

The three control structures: sequence 顺序 runs steps in order, selection 选择 chooses a branch, iteration 迭代 repeats a body.
What is the difference between a variable and a constant?
Difficulty 1/5 · 100 coins + a small bonus on first completion today
A variable's value can change; a constant is set once and never changes.
Match each value to its data type.
Difficulty 2/5 · 140 coins + a small bonus on first completion today
Whole number = integer; decimal = real; text in quotes = string (a single char like 'A' is char).
Sequence and selection
- Sequence — steps run one after another, top to bottom.
- Selection — choose which steps run, with
IF…ELSE(orCASEfor many options):
IF Score >= 50
THEN
OUTPUT "Pass"
ELSE
OUTPUT "Fail"
ENDIF

Variables and constants are named stores for values, set in the program's code.
How an IF … ELSE IF ladder decides
The conditions are tested top to bottom; the FIRST one that is true runs and the rest are skipped. Slide the score and watch which branch lights up.
Which structure chooses which steps to run based on a condition?
Difficulty 1/5 · 100 coins + a small bonus on first completion today
Selection branches on a condition; sequence runs in order; iteration repeats.
Iteration and totalling
- Count-controlled (
FOR) repeats a fixed number of times. - Pre-condition (
WHILE) tests before — may run zero times. Post-condition (REPEAT…UNTIL) tests after — runs at least once. - Totalling:
Total ← Total + Value; counting:Count ← Count + 1.

While a program runs, its variables are held in the computer's memory (RAM).
A WHILE loop tests its condition before the body (so it may run zero times), while a REPEAT...UNTIL loop tests after the body (so it always runs at least once).
Difficulty 1/5 · 100 coins + a small bonus on first completion today
Pre-condition (WHILE) can skip entirely; post-condition (REPEAT) always runs once — choose by whether the body must run at least once.
You've got it
- variable changes, constant is fixed; types: integer, real, char, string, Boolean
- three structures: sequence, selection (IF/CASE), iteration (FOR/WHILE/REPEAT)
- WHILE tests before (0+ times); REPEAT tests after (1+ times)
- totalling = running total; counting = add 1 each time
Which line keeps a running total?
Difficulty 1/5 · 100 coins + a small bonus on first completion today
total ← total + value accumulates the sum; count ← count + 1 counts occurrences.