Editor

Cambridge pseudocode runner

Write pseudocode the way the Cambridge guides do and run it, with an error that points to the line when something is wrong.

Type <- for ← if you prefer the keyboard. Tab indents, Ctrl+Enter runs.

The rules it follows

Every variable is declared
DECLARE Total : INTEGER comes before Total is used. FOR loop counters are the one exception, as in the guides.
Types are checked
Putting a STRING into an INTEGER, or reading a variable before it has a value, stops the program with an error on that line.
Arrays keep their bounds
DECLARE Scores : ARRAY[1:10] OF INTEGER accepts indexes 1 to 10. Index 0 or 11 is an error that names the array and its bounds.
Keywords in capitals
OUTPUT, IF, ENDIF and the rest are written in capitals. Your own names are not case sensitive, so Total and TOTAL are the same variable.
& joins strings
"Total: " & NUM_TO_STR(Total). Use NUM_TO_STR and STR_TO_NUM to move between numbers and text.
BYVAL unless you say BYREF
A parameter is a copy unless it is BYREF, and BYREF carries on to the parameters after it, as in the guides' SWAP example.
Integer division
DIV(17, 5) and 17 DIV 5 both give 3; MOD gives the remainder. / always gives a REAL.
Text files
OPENFILE "data.txt" FOR READ, WRITE or APPEND, then READFILE, WRITEFILE, EOF and CLOSEFILE. The files live in the Text files panel.

Built-in functions

LENGTH(s)Number of characters
LEFT(s, n), RIGHT(s, n)The first or last n characters
MID(s, start, n)n characters from position start (counted from 1); SUBSTRING works too
UCASE, LCASEUpper or lower case, of a character or a whole string
NUM_TO_STR, STR_TO_NUM, IS_NUMNumbers to text and back, and whether text is a number
ASC(c), CHR(n)A character's code, and the character for a code
INT(x), ROUND(x, places)Whole part, and rounding to a number of places
RAND(x), RANDOM()A random REAL from 0 up to x, and from 0 to 1
DAY, MONTH, YEAR, DAYINDEX, SETDATE, NOWDates
EOF(file)TRUE at the end of a file being read

Writing it in Python first? The Python to pseudocode converter drafts it in Cambridge style; add the DECLARE lines and types, then run it here.

Frequently asked questions

Which syllabuses does it follow?
The pseudocode guides Cambridge publishes for teachers of IGCSE and O Level Computer Science (0478 and 2210) and International AS & A Level Computer Science (9618). Where the guides differ, both forms are accepted: LCASE works on a character (9618) or a whole string (0478), and SUBSTRING sits beside MID.
How do I type the arrow?
Press the ← button above the code, or type <- and the runner reads it as the arrow.
Why does it insist on DECLARE?
Because the guides declare every variable, and exam answers are expected to. The runner stops on a missing declaration and says which line to add.
What is not supported yet?
Classes and objects, random files (SEEK, GETRECORD, PUTRECORD), pointer and set types, and TRY ... EXCEPT. Each gives a message saying so rather than a confusing error.
Is my work saved?
Your program and its text files are kept in this browser, so they are still here when you come back. Copy link makes a link to the program to send to a teacher or a friend.
Does it work on a phone or a school computer?
Yes. It runs in the browser, with nothing to install and no account, on Chromebooks, tablets and phones.

More: All pseudocode runners · OCR Exam Reference Language · Python to pseudocode · Python to flowchart

Cambridge IGCSE, Cambridge O Level and Cambridge International AS & A Level are qualifications of Cambridge University Press & Assessment, which is not affiliated with this site and does not endorse it.