Programming basics
| English | Chinese | Pinyin |
|---|---|---|
| variable | 变量 | biàn liàng |
| constant | 常量 | cháng liàng |
| assignment | 赋值 | fù zhí |
| precedence | 优先级 | yōu xiān jí |
| library routines | 库例程 | kù lì chéng |
From design to code
- A design (flowchart or structured English) becomes pseudocode, then a real language.
- Find the variables 变量 and types, turn boxes into statements, then trace a small input to check.
- First, the basic building blocks: variables, expressions and built-in routines.
Constants 常量 and variables
- A constant holds a value that never changes; a variable holds one that may.
CONSTANT Pi ← 3.14159
DECLARE Radius : REAL
Radius ← 5
Area ← Pi * Radius * Radius
- Use constants for fixed recurring values (
Pi,MaxScore) — clearer, and changed in one place.

Programming basics: writing instructions as lines of code.
A constant holds a fixed value that never changes while the program runs, whereas a variable can be reassigned.
Constants (like Pi or a maximum score) make code clearer and let you change a recurring value in one place.
Assignment 赋值 and expressions
- Assignment uses
←:Total ← Total + 1. - Operators: arithmetic
+ - * /, plusDIV(integer division) andMOD(remainder):7 DIV 2 = 3,7 MOD 2 = 1. - Comparisons
= <> < > <= >=; logicAND OR NOT. - Precedence 优先级 (high → low):
NOT→* / DIV MOD→+ -→ comparisons →AND→OR. Use brackets when unsure.

A variable's value can change; a constant stays fixed
A variable is a labelled box
Each assignment stores one value in a named box; reassigning the same name overwrites it. Step through the program and watch each box take its current value.
What is the value of 7 DIV 2?
DIV is integer division: 7 ÷ 2 = 3 remainder 1, so DIV gives 3.
What is the value of 7 MOD 2?
MOD gives the remainder: 7 ÷ 2 leaves remainder 1.
Which symbol assigns a value to a variable in this pseudocode?
Assignment uses ←; = is comparison.
Match each pseudocode operator to what it does.
← stores, = compares; DIV gives the quotient and MOD the remainder (7 DIV 2 = 3, 7 MOD 2 = 1).
Built-in library routines 库例程
- Don't reinvent common tasks — use library routines:
- String:
LENGTH(s),LEFT(s,n),RIGHT(s,n),MID(s,start,len),UCASE(s),LCASE(s). - Numeric:
INT(x),ROUND(x),ABS(x),RANDOM(). - Conversion:
STR(x)(number → string),VAL(s)(string → number). - Code is written from a design given as a program flowchart or structured English.

Move unchanging work out of the loop so it runs once
You've got it
- constant = fixed value; variable = changeable; declare both with a type
- assignment is
←;DIV= integer division,MOD= remainder - precedence:
NOT→* / DIV MOD→+ -→ comparisons →AND→OR - reuse library routines (
LENGTH,ROUND,STR/VAL) instead of rewriting them