Cambridge 0478 pseudocode conventions

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Cambridge 0478 pseudocode conventions

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which line follows Cambridge 0478 pseudocode conventions for keywords?
A FOR Count ← 1 TO 10
B for Count ← 1 to 10
2. Which version shows the correct indentation?
A FOR i ← 1 TO 5 OUTPUT i NEXT i
B FOR i ← 1 TO 5 OUTPUT i NEXT i
3. Which line is a correct Cambridge pseudocode comment?
A Add the mark to the total
B // Add the mark to the total
4. Which layout follows the one statement per line convention?
A Total ← 0 Count ← 0
B Total ← 0 Count ← 0
5. Where should the OUTPUT line be written inside this IF structure?
A IF Mark >= 50 THEN OUTPUT "Pass" ENDIF
B IF Mark >= 50 THEN OUTPUT "Pass" ENDIF

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1// Add each mark to Total AThe keywords if, then and endif are in lower case; Cambridge pseudocode writes them in capitals (IF, THEN, ENDIF)
2FOR Index ← 1 TO 10 BA comment: two slashes start a note for the reader that is not part of the algorithm's steps
3Lines inside a loop or IF are indented so the structure is easy to see CTotal ← 0 Count ← 0
4Each line holds one statement only DThe line inside the WHILE loop is not indented, so the loop body is hard to see
5if Score > 50 then OUTPUT "Pass" endif EFOR Count ← 1 TO 5 OUTPUT Count NEXT Count
6WHILE Num < 10 DO Num ← Num + 1 ENDWHILE FKeywords FOR and TO are written in capital letters so they stand out from variable names

Definitions

UPPERCASE keywords

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
___ Index ← 1 TO 5 OUTPUT Index NEXT Index
2.
IF Score >= 50 ____ OUTPUT "Pass" ENDIF
3.
Total ← 0 __ add each mark to the total Total ← Total + Mark
4.
WHILE Count <= 10 DO Count ← Count + 1 ________
5.
REPEAT Num ← Num + 1 _____ Num = 5

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A Total ← 0
B FOR Count ← 1 TO 3
C Total ← Total + Count
D next Count
E OUTPUT Total
Question 2
A Count ← 0
B while Count < 3 DO
C OUTPUT Count
D Count ← Count + 1
E ENDWHILE
Question 3
A INPUT Mark
B IF Mark >= 50 THEN
C OUTPUT "Pass"
D else
E OUTPUT "Fail"
F ENDIF
Question 4
A DECLARE Total : INTEGER
B # Start the total at zero
C Total ← 0
Question 5
A DECLARE Total : INTEGER
B DECLARE Count : INTEGER
C Total ← 0 Count ← 0
D Count ← 0

Answer Key

Cambridge 0478 pseudocode conventions
Section A: Quick Questions
Q1
A — FOR Count ← 1 TO 10
Q2
A — FOR i ← 1 TO 5 OUTPUT i NEXT i
Q3
B — // Add the mark to the total
Q4
A — Total ← 0 Count ← 0
Q5
B — IF Mark >= 50 THEN OUTPUT "Pass" ENDIF
Section B: Match the Pairs
Q1
// Add each mark to Total → A comment: two slashes start a note for the reader that is not part of the algorithm's steps
Q2
FOR Index ← 1 TO 10 → Keywords FOR and TO are written in capital letters so they stand out from variable names
Q3
Lines inside a loop or IF are indented so the structure is easy to see → FOR Count ← 1 TO 5 OUTPUT Count NEXT Count
Q4
Each line holds one statement only → Total ← 0 Count ← 0
Q5
if Score > 50 then OUTPUT "Pass" endif → The keywords if, then and endif are in lower case; Cambridge pseudocode writes them in capitals (IF, THEN, ENDIF)
Q6
WHILE Num < 10 DO Num ← Num + 1 ENDWHILE → The line inside the WHILE loop is not indented, so the loop body is hard to see
Section C: Definitions
Q1
UPPERCASE keywords — Cambridge pseudocode writes keywords like IF, FOR and WHILE in capitals and indents the lines inside each structure, so the code is easy to read.
Section D: Fill in the Blanks
Q1
FOR Index ← 1 TO 5 OUTPUT Index NEXT Index
Q2
IF Score >= 50 THEN OUTPUT "Pass" ENDIF
Q3
Total ← 0 // add each mark to the total Total ← Total + Mark
Q4
WHILE Count <= 10 DO Count ← Count + 1 ENDWHILE
Q5
REPEAT Num ← Num + 1 UNTIL Num = 5
Section E: Spot the Error
Q1
D — NEXT is a keyword, so Cambridge pseudocode writes it in capital letters. The line should be 'NEXT Count'.
Q2
B — The keyword WHILE is written in lowercase. Cambridge pseudocode keywords are in capital letters, so it should be 'WHILE Count < 3 DO'.
Q3
D — ELSE is a keyword and must be in capital letters. It should be 'ELSE'.
Q4
B — Cambridge pseudocode comments start with //, not #. The # style belongs to Python. It should be '// Start the total at zero'.
Q5
C — Two statements are squeezed onto one line. Cambridge pseudocode uses one statement per line, so this line should be just 'Total ← 0' and 'Count ← 0' stays on its own line.