Pseudocode Conventions in HKDSE

Example 1 β€” Sum of N

INPUT n
total ← 0
FOR i FROM 1 TO n
    total ← total + i
END FOR
OUTPUT total
n = int(input())
total = 0
for i in range(1, n + 1):
    total += i
print(total)

Example 2 β€” Linear Search

found ← FALSE
FOR each x IN list
    IF x = target THEN
        found ← TRUE
        EXIT FOR
    END IF
END FOR
found = False
for x in lst:
    if x == target:
        found = True
        break

Tips

Practise this on PyForm β€” free

PyForm runs Python in your browser with an AI tutor trained for HKDSE. No install, no credit card.

Open PyForm β†’