Variables, constants, and arrays
Declare every variable before use. Arrays may have one or two dimensions, and their bounds are inclusive.
pseudocode
DECLARE Name : STRING
DECLARE Score : INTEGER
CONSTANT PassMark <- 50
DECLARE Results : ARRAY[1:30] OF INTEGER
INPUT Score
Results[1] <- Score
OUTPUT "First score: ", Results[1]Selection and iteration
Use ENDIF, NEXT, ENDWHILE, and UNTIL to close control structures.
pseudocode
DECLARE Index : INTEGER
DECLARE Total : INTEGER
Total <- 0
FOR Index <- 1 TO 10
Total <- Total + Index
NEXT Index
IF Total >= 50 THEN
OUTPUT "Target reached"
ELSE
OUTPUT "Below target"
ENDIFProcedures and functions
Procedures perform a task. Functions return a value that can be used inside an expression.
pseudocode
FUNCTION IsPass(Score : INTEGER) RETURNS BOOLEAN
RETURN Score >= 50
ENDFUNCTION
PROCEDURE ShowResult(Score : INTEGER)
IF IsPass(Score) THEN
OUTPUT "Pass"
ELSE
OUTPUT "Fail"
ENDIF
ENDPROCEDURE
CALL ShowResult(72)Text file handling
The editor uses virtual files, so file algorithms can be practised without accessing files on your computer.
pseudocode
DECLARE Line : STRING
OPENFILE "names.txt" FOR READ
WHILE NOT EOF("names.txt") DO
READFILE "names.txt", Line
OUTPUT Line
ENDWHILE
CLOSEFILE "names.txt"Continue practising
Run these examples in IGCSE mode, then use the trace table to inspect each variable change.