Pro Content

Upgrade to access all Cambridge 9618 lessons including selection, IF/CASE constructs and Boolean logic.

Upgrade to Pro →
← Back to Dashboard
📝 Paper 2 · 2.3 Programming Constructs
2.3.2 Input, Output and Selection
Cambridge 9618 · International A Level Computer Science · ~14 min read
Notes
Video
Slides
Quiz
Worksheet

INPUT and OUTPUT

Cambridge 9618 uses specific keywords for reading user input and displaying output:

// INPUT reads a value from the user into a variable
DECLARE name : STRING
DECLARE age : INTEGER
INPUT name
INPUT age

// OUTPUT displays values to the user
OUTPUT "Hello, ", name
OUTPUT "Your age is: ", age
OUTPUT age + 1  // expressions can be used in OUTPUT

Note: Cambridge 9618 uses INPUT (not READ or SCAN) and OUTPUT (not PRINT or WRITE).

Selection — IF...THEN...ELSE...ENDIF

Selection (branching) lets a program choose different paths depending on a condition.

Basic IF

IF age >= 18 THEN
  OUTPUT "Adult"
ENDIF

IF...ELSE

IF score >= 50 THEN
  OUTPUT "Pass"
ELSE
  OUTPUT "Fail"
ENDIF

Nested IF (chained conditions)

IF score >= 80 THEN
  OUTPUT "A"
ELSE
  IF score >= 60 THEN
    OUTPUT "B"
  ELSE
    IF score >= 40 THEN
      OUTPUT "C"
    ELSE
      OUTPUT "Fail"
    ENDIF
  ENDIF
ENDIF

Cambridge 9618 does not have ELIF or ELSEIF — nest IF inside ELSE instead.

Selection — CASE...OF...OTHERWISE...ENDCASE

CASE is used when a single variable can have several discrete values. It is cleaner than deeply nested IFs for this purpose.

CASE OF grade
  "A" : OUTPUT "Excellent"
  "B" : OUTPUT "Good"
  "C" : OUTPUT "Satisfactory"
  OTHERWISE : OUTPUT "Below standard"
ENDCASE

CASE with INTEGER values

DECLARE day : INTEGER
INPUT day
CASE OF day
  1 : OUTPUT "Monday"
  2 : OUTPUT "Tuesday"
  3 : OUTPUT "Wednesday"
  4 : OUTPUT "Thursday"
  5 : OUTPUT "Friday"
  OTHERWISE : OUTPUT "Weekend"
ENDCASE

Boolean Operators

Conditions can be combined using Boolean operators to create compound conditions:

AND
TRUE only if both conditions are TRUE.
Example: age >= 16 AND age < 18
OR
TRUE if at least one condition is TRUE.
Example: grade = "A" OR grade = "B"
NOT
Inverts a boolean: TRUE becomes FALSE.
Example: NOT (x = 0)

Using AND / OR in IF conditions

// Compound conditions with AND/OR
IF age >= 16 AND hasID = TRUE THEN
  OUTPUT "Access granted"
ENDIF

IF score < 0 OR score > 100 THEN
  OUTPUT "Invalid score"
ENDIF

IF NOT passed THEN
  OUTPUT "Please resit"
ENDIF

Worked Example — Complete Program

// Grade calculator with IF and CASE
DECLARE score : INTEGER
DECLARE grade : CHAR

OUTPUT "Enter your score (0-100): "
INPUT score

IF score < 0 OR score > 100 THEN
  OUTPUT "Error: score out of range"
ELSE
  IF score >= 80 THEN
    grade ← 'A'
  ELSE
    IF score >= 60 THEN
      grade ← 'B'
    ELSE
      grade ← 'C'
    ENDIF
  ENDIF
  CASE OF grade
    'A' : OUTPUT "Distinction"
    'B' : OUTPUT "Merit"
    OTHERWISE : OUTPUT "Pass"
  ENDCASE
ENDIF

IF vs CASE — When to Use Each

Use IF whenUse CASE when
Comparing ranges (e.g., score >= 80)Comparing a single variable against specific discrete values
Complex compound conditions (AND/OR)The variable has several possible exact values (like menu choices)
Checking different variables in each branchAll branches check the same variable for equality
✅ Correct — CASE syntax
CASE OF choice
  1 : OUTPUT "New"
  2 : OUTPUT "Load"
  OTHERWISE : OUTPUT "Exit"
ENDCASE
❌ Wrong — missing OTHERWISE/ENDCASE
CASE OF choice
  1 : OUTPUT "New"
  2 : OUTPUT "Load"
// missing OTHERWISE
// missing ENDCASE
Exam tip: Cambridge 9618 requires exact syntax. CASE must include OTHERWISE (handles all other values) and must be closed with ENDCASE. IF must always end with ENDIF. Cambridge does not use ELIF — use nested IF...ELSE...IF instead. Each ENDIF closes one IF block.
⚠️ Common Mistakes
  • Writing ELIF instead of ELSE followed by another IF (Cambridge 9618 has no ELIF)
  • Forgetting ENDIF — each IF requires its own ENDIF
  • Forgetting OTHERWISE in CASE — examiners expect it
  • Forgetting ENDCASE at the end of CASE block
  • Using PRINT or WRITE instead of OUTPUT
  • Using READ or SCAN instead of INPUT
  • Writing IF (age > 18): — no colon after THEN, no brackets required
✅ Notes completed!
Video coming soon
Click slide or press arrow keys to navigate

Worksheet — 2.3.2 Input/Output & Selection

8 questions · Cambridge 9618 standard

Q1Write pseudocode to ask the user for their name, then output "Hello, " followed by their name.[3]
✅ Mark scheme
DECLARE name : STRING [1]; INPUT name [1]; OUTPUT "Hello, ", name [1].
Q2Write an IF...ELSE...ENDIF statement that outputs "Pass" if a score is 50 or above, and "Fail" otherwise.[4]
✅ Mark scheme
IF score >= 50 THEN [1]; OUTPUT "Pass" [1]; ELSE [1]; OUTPUT "Fail"; ENDIF [1].
Q3Write a CASE OF statement to output a word for a number 1–3: 1 = "One", 2 = "Two", 3 = "Three", anything else = "Unknown". Use variable num.[5]
✅ Mark scheme
CASE OF num [1]; 1 : OUTPUT "One" [1]; 2 : OUTPUT "Two"; 3 : OUTPUT "Three" [1]; OTHERWISE : OUTPUT "Unknown" [1]; ENDCASE [1].
Q4What is the difference between AND and OR in Boolean conditions? Give an example of each.[4]
✅ Mark scheme
AND: both conditions must be TRUE for the overall condition to be TRUE [1]; example: IF age >= 16 AND hasID = TRUE THEN [1]. OR: at least one condition must be TRUE [1]; example: IF grade = "A" OR grade = "B" THEN [1].
Q5Identify and correct all errors in this pseudocode:
IF score > 80
  PRINT "Excellent"
ELIF score > 60
  PRINT "Good"
END
[4]
✅ Mark scheme
Errors: PRINT should be OUTPUT [1]; ELIF should be ELSE (Cambridge has no ELIF) [1]; missing THEN after IF condition [1]; END should be ENDIF (or two ENDIFs for nested IF) [1]. Corrected: IF score > 80 THEN; OUTPUT "Excellent"; ELSE; IF score > 60 THEN; OUTPUT "Good"; ENDIF; ENDIF.
Q6Explain when CASE is more suitable than IF for selection. Give one scenario where IF must be used instead of CASE.[3]
✅ Mark scheme
CASE is more suitable when a single variable is compared against several specific discrete values (e.g., menu choice 1, 2, 3, 4) — cleaner and more readable than nested IF [1]; IF must be used when conditions involve ranges (e.g., score >= 80) [1], compound conditions with AND/OR [1], or comparing different variables in different branches [1]. (Award 3 max.)
Q7Write a FUNCTION called CountChar that takes a STRING and a CHAR as parameters and returns the number of times the character appears in the string. Show a call that counts how many times 'a' appears in "banana".[5]
✅ Mark scheme
FUNCTION CountChar(s : STRING, ch : CHAR) RETURNS INTEGER — 1 mark; DECLARE count : INTEGER — 1 mark; FOR loop from 1 to LENGTH(s) with MID(s,i,1) = ch → count ← count + 1 — 1 mark; RETURN count — 1 mark; call CountChar("banana", 'a') returns 3 — 1 mark.
Q8Explain the difference between string concatenation and string conversion. Write pseudocode to convert the INTEGER 42 to the STRING "42" and then concatenate it with " is the answer" to produce "42 is the answer".[4]
✅ Mark scheme
Concatenation joins strings together — 1 mark; conversion changes a value from one type to another (e.g. INT to STRING) — 1 mark; NUM_TO_STR(42) or INT_TO_STRING(42) produces "42" — 1 mark; result ← NUM_TO_STR(42) & " is the answer" produces "42 is the answer" — 1 mark.
Topic Quiz
Question 1 of 10
You scored
out of 10
Card 1 of 6
Click to reveal definition
🎉
All cards reviewed!
TermDefinition
🎯

Mini Test — 2.3.2 Input/Output & Selection

10 questions · 10 marks · 10 minutes

← 2.3.1 Variables & Constants
42 of 82 · Cambridge 9618
2.4.1 Searching Algorithms →