8.1 Programming

Show All Section Notes

Library Routines & Operators

1. The Three Categories of Operators

A. Arithmetic Operators

These are used to perform mathematical calculations on numerical data types (Integer and Real).

OperatorFunctionExample
+Addition10 + 5 = 15
-Subtraction10 - 5 = 5
*Multiplication10 * 5 = 50
/Division10 / 4 = 2.5
DIVInteger Division (Quotient only)10 DIV 4 = 2
MODModulo (Remainder only)10 MOD 4 = 2

B. Relational (Comparison) Operators

These compare two values and return a Boolean result (TRUE or FALSE). Used in IF statements and Loops.

OperatorFunctionExample
=Equal toX = 10
<>Not equal toX <> 10
>Greater thanX > 10
<Less thanX < 10
>=Greater than or equal toX >= 10
<=Less than or equal toX <= 10

C. Boolean (Logical) Operators

Used to combine multiple conditions together to form complex logic.

OperatorFunctionExample
ANDTrue only if BOTH are true(X > 5) AND (X < 10)
ORTrue if AT LEAST ONE is true(Ans = 'Y') OR (Ans = 'y')
NOTReverses the Boolean valueNOT (X = 10)

2. Official Library Routines (String Handling)

The following are the only string functions recognized in the Cambridge marking schemes:

RoutineFunction
LENGTH(String)Returns the length of the string as an integer.
LCASE(String)Converts all characters to lowercase.
UCASE(String)Converts all characters to uppercase.
SUBSTRING(s, start, length)Extracts a portion of string s starting at start for length.
LEFT(String, n)Returns the first n characters of the string.
RIGHT(String, n)Returns the last n characters of the string.
// Example usage in an algorithm DECLARE MyText : STRING MyText "Cambridge" OUTPUT LENGTH(MyText) // Result: 9 OUTPUT SUBSTRING(MyText, 1, 3) // Result: "Cam"

3. Numeric & Random Routines

RoutineFunction
INT(n)Returns the integer part of value n.
ROUND(n, d)Rounds n to d decimal places.
RANDOM()Returns a random real number between 0 and 1 inclusive.
📝 Exam Note (Very Important):

In Cambridge pseudocode, the Assignment Operator is an arrow: .
Using a single equals sign (=) for assignment is a common mistake; it should only be used for comparison.