Pseudocode layout: capital keywords and indentation

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

Pseudocode layout: capital keywords and indentation

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which line is written in the correct pseudocode style?
A IF score > 10 THEN
B if score > 10 then
2. How should the steps inside an IF block be laid out?
A Lined up with the IF at the left edge
B Indented under the IF line
3. Where should ELSE be placed?
A Lined up directly under its matching IF
B Indented further than the steps above it
4. Which layout follows the one step per line rule?
A SET total TO 0 SET count TO 1
B SET total TO 0 SET count TO 1
5. Which REPEAT block is laid out correctly?
A REPEAT 3 TIMES OUTPUT "Hi"
B REPEAT 3 TIMES OUTPUT "Hi"

Match the Pairs

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

Left columnRight column
1IF score > 10 THEN OUTPUT "Pass" ELSE OUTPUT "Try again" AELSE is indented in line with the steps instead of lining up with its IF. It should start in the same column as IF.
2REPEAT 3 TIMES OUTPUT "Hello" BThe keywords if, then and output are in lowercase. They should be written in capitals: IF, THEN and OUTPUT.
3Write one step per line, with keywords in capitals CThe indented step is repeated; the keywords are in capitals
4Indent a nested block further than the block around it DELSE lines up with its IF, and the steps inside each part are indented
5if age >= 13 then output "Teen" ESET total TO 0 INPUT age OUTPUT age
6IF score > 10 THEN OUTPUT "Pass" ELSE OUTPUT "Try again" FREPEAT 5 TIMES IF key = "Q" THEN OUTPUT "Quit"

Definitions

pseudocode layout

Fill in the Blanks

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

1.
IF score >= 50 THEN OUTPUT "Pass" ____
2.
______ 3 TIMES OUTPUT "Hi" END REPEAT
3.
IF age >= 13 ____ OUTPUT "Teen" END IF
4.
IF raining THEN OUTPUT "Take umbrella" ______
5.
REPEAT count ← count + 1 _____ count = 5

Spot the Error

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

Question 1
A SET age TO 12
B if age >= 13 then
C DISPLAY "Teen"
D ELSE
E DISPLAY "Child"
Question 2
A INPUT mark
B If mark >= 50 Then
C DISPLAY "Pass"
D ELSE
E DISPLAY "Try again"
Question 3
A SET total TO 0
B REPEAT 5 times
C ADD 2 TO total
D DISPLAY total
Question 4
A SET lives TO 3
B REPEAT UNTIL lives = 0
C display lives
D SUBTRACT 1 FROM lives
Question 5
A INPUT name
B SET score TO 0
C DISPLAY name DISPLAY score
D DISPLAY score

Answer Key

Pseudocode layout: capital keywords and indentation
Section A: Quick Questions
Q1
A — IF score > 10 THEN
Q2
B — Indented under the IF line
Q3
A — Lined up directly under its matching IF
Q4
A — SET total TO 0 SET count TO 1
Q5
B — REPEAT 3 TIMES OUTPUT "Hi"
Section B: Match the Pairs
Q1
IF score > 10 THEN OUTPUT "Pass" ELSE OUTPUT "Try again" → ELSE lines up with its IF, and the steps inside each part are indented
Q2
REPEAT 3 TIMES OUTPUT "Hello" → The indented step is repeated; the keywords are in capitals
Q3
Write one step per line, with keywords in capitals → SET total TO 0 INPUT age OUTPUT age
Q4
Indent a nested block further than the block around it → REPEAT 5 TIMES IF key = "Q" THEN OUTPUT "Quit"
Q5
if age >= 13 then output "Teen" → The keywords if, then and output are in lowercase. They should be written in capitals: IF, THEN and OUTPUT.
Q6
IF score > 10 THEN OUTPUT "Pass" ELSE OUTPUT "Try again" → ELSE is indented in line with the steps instead of lining up with its IF. It should start in the same column as IF.
Section C: Definitions
Q1
pseudocode layout — Write keywords like IF, THEN, ELSE and REPEAT in capitals, one step per line, and indent the steps inside each structure so ELSE lines up with its IF.
Section D: Fill in the Blanks
Q1
IF score >= 50 THEN OUTPUT "Pass" ELSE
Q2
REPEAT 3 TIMES OUTPUT "Hi" END REPEAT
Q3
IF age >= 13 THEN OUTPUT "Teen" END IF
Q4
IF raining THEN OUTPUT "Take umbrella" END IF
Q5
REPEAT count ← count + 1 UNTIL count = 5
Section E: Spot the Error
Q1
B — Pseudocode keywords must be written in capitals. IF and THEN should be written as: IF age >= 13 THEN.
Q2
B — Keywords must be all capitals, not just start with a capital letter. It should be: IF mark >= 50 THEN.
Q3
B — TIMES is a keyword, so it must be in capitals like REPEAT. The line should be: REPEAT 5 TIMES.
Q4
C — DISPLAY is a keyword, so it must be in capitals even when it is indented inside the loop. It should be: ' DISPLAY lives'.
Q5
C — Pseudocode has one step per line. The two DISPLAY steps must be split onto separate lines.