Operators, strings and subroutines
Introduced| English | Meaning |
|---|---|
| operators/ˈɒpəreɪtəz/ | Symbols or keywords specifying operations to perform on values or expressions. |
| procedure/prəˈsiːdʒə/ | A named sequence of instructions that performs a task when called. |
| function/ˈfʌŋkʃn/ | A mapping that assigns exactly one output to each allowed input. |
| relational/rɪˈleɪʃənl/ | relational |
| logical/ˈlɒdʒɪkl/ | logical |
| parameter/pəˈræmɪtə/ | A value that specifies a particular member of a family of functions, models or systems. |
| local variable/ˈləʊkl ˈveərɪəbl/ | A variable whose name is accessible only within a particular function, block or other limited scope. |
| global/ˈɡləʊbl/ | global |
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?
Difficulty 2/5 · 140 coins + a small bonus on first completion today
MOD gives the remainder: 17 ÷ 5 = 3 remainder 2.
What is 17 DIV 5?
Difficulty 2/5 · 140 coins + a small bonus on first completion today
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
SUBSTRING: take part of a string
The first character is at position 1. SUBSTRING(Word, Start, Length) takes Length characters beginning at Start — drag the two handles and read the call it builds.
What does LENGTH("Computer") return?
Difficulty 2/5 · 140 coins + a small bonus on first completion today
"Computer" has 8 characters.
Match each operator or string function to what it gives.
Difficulty 2/5 · 140 coins + a small bonus on first completion today
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:
Difficulty 1/5 · 100 coins + a small bonus on first completion today
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.
Difficulty 1/5 · 100 coins + a small bonus on first completion today
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