Skip to content

B1 · Pseudocode

Spec reference: Section B - Standard Methods in Algorithm Development
Key idea: Express algorithms in structured, language-independent notation.


Pseudocode


Pseudocode conventions for BTEC

There is no single universal standard for pseudocode, but the BTEC exam typically uses these conventions:

Variables and assignment

SET name TO "Alice"
SET score TO 0
SET total TO score + 10

Input and output

RECEIVE name FROM KEYBOARD
SEND "Hello, " & name TO DISPLAY

Arithmetic operators

SymbolMeaning
+Add
-Subtract
*Multiply
/Divide
MODRemainder (modulus)
DIVInteger division
^Power/exponent

Comparison operators

SymbolMeaning
=Equal to
Not equal to
<Less than
>Greater than
Less than or equal to
Greater than or equal to

Selection (IF statements)

IF score >= 70 THEN
    SEND "Grade A" TO DISPLAY
ELSE IF score >= 60 THEN
    SEND "Grade B" TO DISPLAY
ELSE
    SEND "Grade C" TO DISPLAY
END IF

Iteration (loops)

WHILE loop (condition checked before each iteration)

SET count TO 0
WHILE count < 5 DO
    SEND count TO DISPLAY
    SET count TO count + 1
END WHILE

FOR loop (known number of iterations)

FOR i FROM 1 TO 10 DO
    SEND i TO DISPLAY
END FOR

REPEAT...UNTIL loop (condition checked after each iteration)

REPEAT
    RECEIVE password FROM KEYBOARD
UNTIL password = correctPassword

Procedures and functions

PROCEDURE greet(name)
    SEND "Hello, " & name TO DISPLAY
END PROCEDURE

FUNCTION square(n)
    RETURN n * n
END FUNCTION

Worked example: Login system

Problem: A user has 3 attempts to enter the correct password. After 3 failures, lock the account.

SET attempts TO 0
SET locked TO FALSE
SET correctPassword TO "SecurePass1"

WHILE attempts < 3 AND locked = FALSE DO
    RECEIVE enteredPassword FROM KEYBOARD
    IF enteredPassword = correctPassword THEN
        SEND "Access granted" TO DISPLAY
        SET locked TO TRUE
    ELSE
        SET attempts TO attempts + 1
        SEND "Incorrect password. Attempt " & attempts & " of 3" TO DISPLAY
    END IF
END WHILE

IF attempts = 3 THEN
    SEND "Account locked. Contact support." TO DISPLAY
END IF

Trace table for inputs: "wrong", "wrong", "wrong"

attemptsenteredPasswordlockedOutput
0"wrong"FALSE"Incorrect. Attempt 1 of 3"
1"wrong"FALSE"Incorrect. Attempt 2 of 3"
2"wrong"FALSE"Incorrect. Attempt 3 of 3"
3-FALSE"Account locked."

Tips for exam pseudocode questions

  • Always use the constructs shown above (SET, RECEIVE, SEND, IF, WHILE, FOR).
  • Indent nested blocks - unindented pseudocode is very hard to follow.
  • Use meaningful variable names - score not x.
  • Include END IF / END WHILE / END FOR to close every block.
  • A trace table question = step through each line manually and record variable values.

Test Yourself

Question 1 of 5

What is the main purpose of pseudocode?

Ad

PassMaven - revision made simple.