A pseudocode solution is a sequence of steps using keywords such as INPUT,
OUTPUT, IF, FOR, and assignments.
There is no single global “main” keyword: you usually list declarations and
constants first, then define procedures and functions (if any),
then write the main algorithm that calls them.
<- or the arrow character ← (both accepted).// or # are ignored.PROCEDURE … ENDPROCEDURE and FUNCTION … ENDFUNCTION are written at the top level (not nested inside another routine in the current tool).// Example skeleton DECLARE count : INTEGER CONSTANT maxVal <- 100 PROCEDURE showTitle OUTPUT "My program" ENDPROCEDURE CALL showTitle count <- 0
In examinations, types are written after a colon in DECLARE lines. Typical types:
TRUE / FALSE.Expressions may use relational operators =, <>, <, >, <=, >=, and logic AND, OR, NOT. Integer division and remainder are written as DIV and MOD in pseudocode.
DECLARE score : INTEGER DECLARE ok : BOOLEAN score <- 17 ok <- (score >= 10) AND (score MOD 2 = 1)
Use DECLARE with one identifier or several separated by commas, each group sharing one type:
DECLARE total : INTEGER DECLARE firstName, lastName : STRING DECLARE done : BOOLEAN
CONSTANT pi <- 3.142 CONSTANT appName <- "Pseudocode IDE"
In CIE-style pseudocode, a 1D array is declared with a colon between the lower and upper index, for example
ARRAY[lower:upper] OF type. Elements are read or written with subscripts, e.g. List[i].
(This classroom IDE also accepts .. between bounds for compatibility.)
DECLARE List : ARRAY[1:10] OF INTEGER DECLARE i : INTEGER FOR i <- 1 TO 10 List[i] <- i * 2 NEXT i
A 2D array can be declared with two index ranges (rows and columns). Access uses two subscripts, e.g. Grid[r, c].
DECLARE Grid : ARRAY[1:4,1:5] OF INTEGER
DECLARE r : INTEGER
DECLARE c : INTEGER
FOR r <- 1 TO 4
FOR c <- 1 TO 5
Grid[r, c] <- r + c
NEXT c
NEXT r
ARRAY[lo:hi] OF … (and 2D with comma-separated ranges) with subscripted read/write.
For homework and exams, use the same notation on paper; test in the IDE when needed.
Use OUTPUT or PRINT (both are treated the same in the IDE). List one or more values separated by commas; they are shown on one line, separated by spaces.
OUTPUT "Hello" OUTPUT "Answer = ", total PRINT name, " ", score
"like this" (single quotes are also accepted for simple literals in the IDE).OUTPUT statement for each line you want on screen.INPUT on the next (in the IDE, the input box or prompt can follow the last message shown).OUTPUT "Name: ", userName OUTPUT "Score: ", marks OUTPUT "" OUTPUT "Done."
A procedure groups statements under a name. It does not return a value to an expression; use it for actions (printing, updating values passed by reference, etc.).
PROCEDURE lineOfStars (count : INTEGER)
DECLARE j : INTEGER
FOR j <- 1 TO count
OUTPUT "*"
NEXT j
OUTPUT ""
ENDPROCEDURE
Parameters are listed in parentheses with types. Use BYREF for reference parameters (see section 8).
PROCEDURE reset (BYREF value : INTEGER) value <- 0 ENDPROCEDURE
A function returns a single value. The header ends with RETURNS type. Inside the function, RETURN followed by an expression sends the value back.
FUNCTION doubleIt (n : INTEGER) RETURNS INTEGER RETURN n * 2 ENDFUNCTION FUNCTION areaOfRectangle (width : REAL, height : REAL) RETURNS REAL RETURN width * height ENDFUNCTION
A function with no parameters:
FUNCTION readPinCode RETURNS INTEGER DECLARE code : INTEGER OUTPUT "Enter code" INPUT code RETURN code ENDFUNCTION
CALLUse CALL followed by the procedure name. Parentheses are optional when there are no arguments.
CALL lineOfStars (10) CALL lineOfStars(5) CALL showTitle
Functions are called like built-in functions: use their name and arguments where a value is needed.
DECLARE x : INTEGER x <- doubleIt(7) OUTPUT "Twice 7 = ", x OUTPUT "Area = ", areaOfRectangle(4.0, 5.5)
If a parameter is declared without BYREF, the argument expression is evaluated and the procedure or function receives a copy. Changing the parameter inside the routine does not change the caller’s variable.
PROCEDURE tryChange (n : INTEGER) n <- 99 ENDPROCEDURE DECLARE a : INTEGER a <- 1 CALL tryChange(a) OUTPUT a // still 1
BYREF
With BYREF, the caller passes a variable name (not a complex expression). The routine works on the same storage as that variable, so updates are visible after the call. In the IDE, the argument must be a simple identifier.
PROCEDURE addBonus (BYREF score : INTEGER) score <- score + 10 ENDPROCEDURE DECLARE mark : INTEGER mark <- 40 CALL addBonus(mark) OUTPUT mark // 50
PROCEDURE adjust (value : INTEGER, BYREF total : INTEGER) total <- total + value ENDPROCEDURE DECLARE sum : INTEGER sum <- 100 CALL adjust(25, sum) OUTPUT sum // 125