Constants, records, and arrays
A-Level constants use =. A previously declared integer constant can be used as an array bound.
pseudocode
TYPE StudentRecord
DECLARE StudentID : STRING
DECLARE Score : INTEGER
ENDTYPE
CONSTANT MaxStudents = 100
DECLARE Students : ARRAY[1:MaxStudents] OF StudentRecord
Students[1].StudentID <- "S001"
Students[1].Score <- 84Array parameters and BYREF
Use BYREF when a procedure must update the caller’s variable or array.
pseudocode
CONSTANT MaxItems = 10
PROCEDURE ClearScores(
BYREF Scores : ARRAY[1:MaxItems] OF INTEGER
)
DECLARE Index : INTEGER
FOR Index <- 1 TO MaxItems
Scores[Index] <- 0
NEXT Index
ENDPROCEDUREFunctions and strict typing
Functions declare a return type and must return a compatible value. Conditions must evaluate to BOOLEAN.
pseudocode
FUNCTION CalculateGrade(Score : INTEGER) RETURNS CHAR
IF Score >= 80 THEN
RETURN 'A'
ELSE
RETURN 'F'
ENDIF
ENDFUNCTION
OUTPUT CalculateGrade(86)Text and random files
Text files support sequential reading and writing. Random files use records with SEEK, GETRECORD, and PUTRECORD.
pseudocode
DECLARE Student : StudentRecord
OPENFILE "students.dat" FOR RANDOM
SEEK "students.dat", 1
GETRECORD "students.dat", Student
CLOSEFILE "students.dat"
OUTPUT Student.StudentIDImportant differences from IGCSE mode
- Constants use
CONSTANT name = value. WHILEdoes not use theDOkeyword.- Procedure calls require
CALL. DIVandMODare infix operators.- A-Level string functions include
MID,LEFT, andRIGHT.