Programming basics
| English | Chinese | Pinyin |
|---|---|---|
| variable | 变量 | biàn liàng |
| data type | 数据类型 | shù jù lèi xíng |
| constant | 常量 | cháng liàng |
| flowchart | 流程图 | liú chéng tú |
| structured English | 结构化英语 | jié gòu huà yīng yǔ |
| pseudocode | 伪代码 | wěi dài mǎ |
| assignment | 赋值 | fù zhí |
| identifier | 标识符 | biāo shí fú |
| operators | 运算符 | yùn suàn fú |
| precedence | 优先级 | yōu xiān jí |
| concatenation | 拼接 | pīn jiē |
| library routines | 库例程 | kù lì chéng |
| program library | 程序库 | chéng xù kù |
| insert | 附页 | fù yè |
The number that did not fit
- On 4 June 1996 the first Ariane 5 rocket veered off course and destroyed itself 37 seconds after launch, with four satellites on board.
- The cause was one conversion: a 64-bit decimal value describing the rocket's sideways speed was copied into a 16-bit integer. Ariane 5 was faster than Ariane 4, the number was too big for the box, and the guidance computer shut down.
- Every variable has a data type 数据类型, and the type decides what fits. Choosing it is the first job in turning a design into code.
- This lesson is the basics: constants, variables, types, expressions, input and output, and the ready-made routines you may call.
From design to code
- A design arrives as a flowchart 流程图 or as structured English 结构化英语. You turn it into pseudocode 伪代码, and later into a real language.
- Find the variables 变量 and their types. Input and output boxes become
INPUTandOUTPUT; decision diamonds becomeIF … ELSE … ENDIForCASE; loop arrows becomeWHILE,REPEAT … UNTILorFOR; process boxes become assignments. - Check by tracing a small input through your pseudocode before you call it finished.

Each flowchart symbol becomes one kind of pseudocode statement
Constants and variables
- A constant 常量 holds a value that never changes while the program runs:
CONSTANT Pi ← 3.14159. A variable holds one that may change, and is declared with a type:DECLARE Radius : REAL. - Use a constant for a fixed value that appears in several places, such as a tax rate or a maximum score.
- The benefits the mark scheme lists: it is set once and cannot be changed accidentally; a change is made in one place and reaches every statement that uses it; the identifier 标识符 gives the value a meaningful name.

A variable can be reassigned; a constant cannot
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.
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.
Which are benefits of using a constant for a value such as a tax rate? Select all that apply.
The three mark-scheme benefits are safety, a single point of change, and readability. Speed is not one of them.
The six data types
INTEGERfor whole numbers (a count, an index, a loop counter).REALfor numbers with a fractional part (a price, an average).CHARfor one character in single quotes,'A'.STRINGfor text in double quotes,"Hello".BOOLEANforTRUEorFALSE(a flag such asFound).DATEfor a calendar date.- Read the type off how the variable is used: a decimal point means
REAL,TRUEmeansBOOLEAN, single quotes meanCHAR, an array index orDIVandMODmeanINTEGER. Write the type in capitals as the guide spells it.
Worked example: state the appropriate data type
Found ← FALSEisBOOLEAN: it holds a truth value.Initial ← 'K'isCHAR: one character in single quotes.Name ← "Li Wei"isSTRING: text in double quotes.Price ← 12.99isREAL: it has a fractional part.Count ← Count + 1isINTEGER: a counter that goes up in whole steps.- One mark per correct type, so answer every row even when unsure; a blank cannot score.
Match each value to the data type its variable should be declared with.
A decimal point, single quotes, double quotes and a truth value each point to one type.
Assignment and expressions
- Assignment 赋值 uses the arrow:
Total ← Total + 1,Average ← Sum / Count. - Arithmetic operators 运算符 are
+ - * /, plusDIVfor whole-number division andMODfor the remainder:7 DIV 2 = 3and7 MOD 2 = 1. - Comparisons are
=,<>,<,>,<=,>=; logic isAND,OR,NOT. - Precedence 优先级, highest first:
NOT, then* / DIV MOD, then+ -, then comparisons, thenAND, thenOR. Use brackets when unsure.
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).
Input and output
OUTPUT "Enter your name:"prompts;INPUT Namereads the keyboard into the variable;OUTPUT "Hello, ", Nameprints several items separated by commas.- Strings are joined with
&, called concatenation 拼接:"A" & "BC"is"ABC". - Keep the quotes straight:
"7"is a string,7is a number, and'7'is a single character.
Built-in functions and library routines
- A program library 程序库 holds routines that are already written, compiled and tested; calling one is faster and safer than writing your own. The Paper 2 insert 附页 lists the library routines 库例程 you may use, with their exact names.
- Strings:
LENGTH(s),LEFT(s, n),RIGHT(s, n),MID(s, start, n)with positions counted from 1,TO_UPPER(s),TO_LOWER(s). Conversion:NUM_TO_STR(x),STR_TO_NUM(s),IS_NUM(s),ASC(c),CHR(n). - Numbers and dates:
INT(x)cuts to the whole part;RAND(n)gives a real from 0 up to but not including n, soINT(RAND(6)) + 1is a dice roll;DAY,MONTH,YEAR,DAYINDEX,SETDATE,TODAY;EOF(f)for files.

The common string routines on s = "COMPUTER", positions 1 to 8
Which routine converts a string to capitals in 9618 pseudocode?
UCASE is the IGCSE name and is not accepted here. Use the exact names printed in the Paper 2 insert.
Worked example: evaluate each expression
- Given
Word ← "Program",Code ← 'Q'andN ← 7. Work from the inside out. LENGTH(Word)is7.MID(Word, 4, 2)is"gr": two characters from position 4.LEFT(Word, 3) & "!"is"Pro!".TO_UPPER(RIGHT(Word, 2))is"AM": the inner function runs first.ASC(Code) - ASC('A')is16, because'Q'is 81 and'A'is 65.N DIV 2 + N MOD 2is3 + 1 = 4.NUM_TO_STR(N) & "th"is"7th".INT(N / 2)is3, the whole part of 3.5.
With Word ← "Program", the value of MID(Word, 4, 2) is "____".
Positions count from 1: P-r-o-g-r-a-m, so position 4 is g and two characters from there are gr.
Worked example: find the error
- Each statement may misuse a function or an operator. Describe the error, or write NO ERROR.
Result ← 2 & 4:&joins strings, but 2 and 4 are integers, so+is needed.SubString ← MID("pseudocode", 4, 1): NO ERROR, one character from position 4,"u".Answer ← LENGTH(42):LENGTHtakes a string, not an integer.Flag ← "TRUE": a Boolean isTRUEwithout quotes; with quotes it is a string.
Result ← 2 & 4 correctly stores 6 in Result.
& joins strings. For two integers the operator is +; this is the error the exam asks you to describe.
Marks that slip away
- The IGCSE names
UCASE,LCASE,VALandSTRare not accepted at A Level. UseTO_UPPER,TO_LOWER,STR_TO_NUM,NUM_TO_STR. - Single quotes make a
CHAR, double quotes make aSTRING.'A'and"A"are different types. - String positions start at 1, not 0.
MID(s, 1, 1)is the first character. RAND(n)never returns n itself, andINTcuts off the fraction rather than rounding.
You've got it
- design → pseudocode: find the variables and types, then map each flowchart symbol to a statement and trace a small input
- constant set once, changed in one place, named; variable declared with one of six types read off how it is used
←assigns;DIVwhole-number division,MODremainder; precedenceNOT→* / DIV MOD→+ -→ comparisons →AND→OR- use the insert's library routines with their exact 9618 names:
LENGTH,MID,TO_UPPER,NUM_TO_STR,INT,RAND