Coding Sheets, Practice & Learning Support: Quick Reference Pseudocode Sheet For AS Level (Copy)
Quick Reference Pseudocode Sheet For AS Level
Purpose Of This Sheet
- Designed as a fast lookup / revision sheet
- Contains:
- Core pseudocode structures
- Standard patterns repeatedly used in exams
- Meant to be:
- Memorised
- Reproduced quickly under exam pressure
- All pseudocode follows Cambridge-style conventions
Basic Syntax Rules (Must Follow)
Assignment
variable ← value
Input / Output
INPUT variable
OUTPUT variable
Comparison Operators
| Meaning | Operator |
|---|---|
| Equal to | = |
| Not equal | <> |
| Greater than | > |
| Less than | < |
| Greater or equal | >= |
| Less or equal | <= |
Selection (IF Statements)
IF Only
IF condition THEN
statement
ENDIF
IF–ELSE
IF condition THEN
statement1
ELSE
statement2
ENDIF
Nested IF
IF condition1 THEN
IF condition2 THEN
statement
ENDIF
ENDIF
Written and Compiled By Sir Hunain Zia (AYLOTI), World Record Holder With 154 Total A Grades, 7 Distinctions and 11 World Records For Educate A Change AS Level Computer Science Full Scale Course
Iteration (Loops)
FOR Loop (Fixed Count)
FOR i ← 1 TO n
statement
NEXT i
WHILE Loop (Entry-Controlled)
WHILE condition DO
statement
ENDWHILE
REPEAT UNTIL Loop (Exit-Controlled)
REPEAT
statement
UNTIL condition
Validation Templates
Range Validation (REPEAT UNTIL)
REPEAT
INPUT value
UNTIL value >= min AND value <= max
Option Validation
REPEAT
INPUT option
UNTIL option = 1 OR option = 2 OR option = 3
Counters And Accumulators
Counter Template
count ← 0
FOR i ← 1 TO n
IF condition THEN
count ← count + 1
ENDIF
NEXT i
Accumulator Template
total ← 0
FOR i ← 1 TO n
INPUT value
total ← total + value
NEXT i
Written and Compiled By Sir Hunain Zia (AYLOTI), World Record Holder With 154 Total A Grades, 7 Distinctions and 11 World Records For Educate A Change AS Level Computer Science Full Scale Course
Average Calculation
Average Of All Values
total ← 0
FOR i ← 1 TO n
INPUT value
total ← total + value
NEXT i
average ← total / n
OUTPUT average
Average Of Selected Values
total ← 0
count ← 0
FOR i ← 1 TO n
INPUT value
IF condition THEN
total ← total + value
count ← count + 1
ENDIF
NEXT i
IF count > 0 THEN
average ← total / count
OUTPUT average
ENDIF
Maximum And Minimum
Maximum
INPUT value
max ← value
FOR i ← 2 TO n
INPUT value
IF value > max THEN
max ← value
ENDIF
NEXT i
OUTPUT max
Minimum
INPUT value
min ← value
FOR i ← 2 TO n
INPUT value
IF value < min THEN
min ← value
ENDIF
NEXT i
OUTPUT min
Written and Compiled By Sir Hunain Zia (AYLOTI), World Record Holder With 154 Total A Grades, 7 Distinctions and 11 World Records For Educate A Change AS Level Computer Science Full Scale Course
Sentinel-Controlled Input
REPEAT UNTIL Sentinel
REPEAT
INPUT value
IF value <> sentinel THEN
PROCESS value
ENDIF
UNTIL value = sentinel
WHILE Sentinel
INPUT value
WHILE value <> sentinel DO
PROCESS value
INPUT value
ENDWHILE
Flag Variables
Detection Flag
flag ← FALSE
FOR i ← 1 TO n
IF condition THEN
flag ← TRUE
ENDIF
NEXT i
Early Exit Using Flag
flag ← FALSE
i ← 1
WHILE i <= n AND flag = FALSE DO
IF condition THEN
flag ← TRUE
ELSE
i ← i + 1
ENDIF
ENDWHILE
Arrays
One-Dimensional Array Declaration
DECLARE arr : ARRAY[1..n] OF INTEGER
Input Into Array
FOR i ← 1 TO n
INPUT arr[i]
NEXT i
Traversing Array
FOR i ← 1 TO n
PROCESS arr[i]
NEXT i
Written and Compiled By Sir Hunain Zia (AYLOTI), World Record Holder With 154 Total A Grades, 7 Distinctions and 11 World Records For Educate A Change AS Level Computer Science Full Scale Course
Linear Search
found ← FALSE
i ← 1
WHILE i <= n AND found = FALSE DO
IF arr[i] = target THEN
found ← TRUE
ELSE
i ← i + 1
ENDIF
ENDWHILE
Bubble Sort (Ascending)
FOR pass ← 1 TO n - 1
FOR j ← 1 TO n - pass
IF arr[j] > arr[j + 1] THEN
temp ← arr[j]
arr[j] ← arr[j + 1]
arr[j + 1] ← temp
ENDIF
NEXT j
NEXT pass
String Handling
String Length
length ← LENGTH(text)
Character Access
char ← text[i]
Character-by-Character Processing
FOR i ← 1 TO LENGTH(text)
PROCESS text[i]
NEXT i
Written and Compiled By Sir Hunain Zia (AYLOTI), World Record Holder With 154 Total A Grades, 7 Distinctions and 11 World Records For Educate A Change AS Level Computer Science Full Scale Course
Nested Loops
FOR row ← 1 TO rows
FOR col ← 1 TO cols
PROCESS table[row][col]
NEXT col
NEXT row
Input–Process–Output Master Skeleton
initialise variables
REPEAT / FOR / WHILE
INPUT
IF condition THEN
PROCESS
ENDIF
END LOOP
FINAL CALCULATION
OUTPUT
Common Exam Reminders (Ultra-High Yield)
- Initialise all variables
- Validate before processing
- Use flags for detection, counters for quantity
- Sentinel values must not be processed
- Keep logic simple and structured
