Operators, strings and subroutines
| English | Chinese | Pinyin |
|---|---|---|
| operators | 运算符 | yùn suàn fú |
| procedure | 过程 | guò chéng |
| function | 函数 | hán shù |
| relational | 关系 | guān xì |
| logical | 逻辑 | luó jí |
| parameter | 参数 | cān shù |
| local variable | 局部变量 | jú bù biàn liàng |
| global | 全局 | quán jú |
The tools of a program
- Programs combine values with operators 运算符 and work with strings.
- To avoid repeating code, we use procedures 过程 and functions 函数.
- Good naming and comments make a program maintainable.
Operators
- Arithmetic:
+ - * /,^(power),MOD(remainder),DIV(whole-number part). e.g.17 MOD 5 = 2,17 DIV 5 = 3. - Relational 关系 (give a Boolean):
= < <= > >= <>(not equal). - Logical 逻辑:
AND(both true),OR(at least one),NOT(reverses).

A pre-condition (WHILE) loop tests before the body, so it may run zero times; a post-condition (REPEAT) loop tests after, so it runs at least once.
What is 17 MOD 5?
MOD gives the remainder: 17 ÷ 5 = 3 remainder 2.
What is 17 DIV 5?
DIV gives the whole-number part: 17 ÷ 5 = 3 (remainder discarded).
String handling
- A string is made of characters. Useful operations:
- LENGTH (number of characters), SUBSTRING (a part), UCASE (capitals), LCASE (small).
name ← "Computer"
OUTPUT LENGTH(name) // 8
OUTPUT SUBSTRING(name, 1, 4) // "Comp"

A variable is a named store whose value can change
Index and slice a string
Every character has a position (index). A slice takes the characters from the start index up to — but not including — the end index, just like SUBSTRING does.
What does LENGTH("Computer") return?
"Computer" has 8 characters.
Match each operator or string function to what it gives.
MOD/DIV split a division into remainder and quotient; LENGTH and SUBSTRING work on strings.
Procedures, functions and good style
- A procedure does a task (run with
CALL); a function returns a value. - A parameter 参数 is a value passed in (up to three).
- A local variable 局部变量 exists only inside its subroutine (safer); a global 全局 is visible everywhere.
- Library routines:
MOD,DIV,ROUND,RANDOM. - A maintainable program uses meaningful names, comments, and subroutines.

The basic data types: integer, real, char, string and boolean
A local variable:
Locals are safer because other parts of the program cannot change them by mistake.
A function returns a value (used in an expression) while a procedure just performs a task, and a local variable can only be used inside the subroutine where it is declared.
Functions return values; locals keep variables safe inside their own subroutine — both make code easier to maintain.
You've got it
MOD= remainder,DIV= whole-number part; logicalAND/OR/NOT- strings: LENGTH, SUBSTRING, UCASE, LCASE
- a procedure does a task; a function returns a value; parameters pass values in
- local variables are safer than global; maintainable = meaningful names + comments + subroutines