SLIDE 1
CSZone.co.uk
Click to advance · Arrow keys also work
CAIE 9618 · Paper 2 · Topic 2.1.2

Pseudocode &
Programming Constructs

CAIE Pseudocode Standard · Sequence · Selection · Iteration

CSZone Cambridge International AS & A Level Computer Science 9618
CAIE Pseudocode Basics

Assignment, Input & Output

ASSIGNMENT
x <- 5
name <- "Ali"
total <- price * qty
INPUT / OUTPUT
INPUT age
OUTPUT "Hello", name
VARIABLES & DECLARATIONS
DECLARE score : INTEGER
DECLARE name : STRING
DECLARE flag : BOOLEAN
CONCATENATION
message <- "Hi " & name
OUTPUT message
Selection

IF…THEN…ELSE and CASE

IF…THEN…ELSE…ENDIF
IF score >= 50
THEN
OUTPUT "Pass"
ELSE
OUTPUT "Fail"
ENDIF
CASE…OF…OTHERWISE…ENDCASE
CASE OF grade
'A' : OUTPUT "Excellent"
'B' : OUTPUT "Good"
'C' : OUTPUT "Pass"
OTHERWISE : OUTPUT "Fail"
ENDCASE
Use CASE when checking one variable against multiple discrete values. Use IF-ELSE-IF when conditions involve comparisons or boolean expressions.
Iteration

FOR, WHILE and REPEAT

FOR…NEXT (count-controlled)
FOR i <- 1 TO 10
OUTPUT i
NEXT i
WHILE…DO…ENDWHILE (pre-condition)
WHILE x > 0 DO
OUTPUT x
x <- x - 1
ENDWHILE
REPEAT…UNTIL (post-condition)
REPEAT
INPUT answer
UNTIL answer = "yes"
Key difference: WHILE tests condition before entering loop (may not execute at all). REPEAT tests condition after (always executes at least once).
Boolean Logic in Pseudocode

Operators and Expressions

COMPARISON OPERATORS
= equal to
<> not equal to
< less than
> greater than
<= less than or equal
>= greater than or equal
LOGICAL OPERATORS
AND, OR, NOT
// e.g.:
IF age >= 18 AND hasID = TRUE
THEN OUTPUT "Access granted"
ENDIF
DIV AND MOD
17 DIV 5 = 3 // integer division
17 MOD 5 = 2 // remainder
Exam Practice

Cambridge-style questions

Question 1
Write pseudocode that reads 10 numbers from the user and outputs the largest value entered. Use a FOR loop.
4 marks
DECLARE largest, num, i : INTEGER
INPUT largest // seed with first value
FOR i <- 2 TO 10
INPUT num
IF num > largest THEN
largest <- num
ENDIF
NEXT i
OUTPUT "Largest: ", largest
Common Mistakes

Don't lose easy marks

1
Using = for assignment in pseudocode — CAIE pseudocode uses <- (left arrow) for assignment, and = for comparison. Writing x = 5 instead of x <- 5 is an error.
2
Forgetting to close loops and conditionals — every FOR needs a NEXT, every WHILE needs an ENDWHILE, every IF needs ENDIF, every CASE needs ENDCASE. Missing these will lose marks.
3
Choosing the wrong loop type — use FOR when you know how many iterations. Use WHILE when condition must be checked before entering (may not run). Use REPEAT-UNTIL when loop body must run at least once (e.g. input validation).
Topic Summary — 2.1.2

What You Need to Know

ASSIGNMENT & I/O
x <- value (not =)
INPUT / OUTPUT keywords
DECLARE name : TYPE
SELECTION
IF-THEN-ELSE-ENDIF
CASE OF-OTHERWISE-ENDCASE
Operators: = <> < > <= >=
ITERATION
FOR i <- 1 TO n ... NEXT i
WHILE cond DO ... ENDWHILE
REPEAT ... UNTIL cond
AND/OR/NOT · DIV/MOD
CSZone

Next Video

2.1.3
Searching Algorithms
Linear Search · Binary Search · Comparison
Head to CSZone.co.uk for the complete worksheet, quiz, and interactive tools