Programming concepts — data and control structures
| English | Chinese | Pinyin |
|---|---|---|
| variable | 变量 | biàn liàng |
| constant | 常量 | cháng liàng |
| data type | 数据类型 | shù jù lèi xíng |
| integer | 整数 | zhěng shù |
| real | 实数 | shí shù |
| string | 字符串 | zì fú chuàn |
| Boolean | 布尔值 | bù ěr zhí |
| sequence | 顺序 | shùn xù |
| selection | 选择 | xuǎn zé |
| iteration | 迭代 | dié dài |
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?
A variable's value can change; a constant is set once and never changes.
Match each value to its data type.
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?
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).
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?
total ← total + value accumulates the sum; count ← count + 1 counts occurrences.