← QCE Digital Solutions Unit 2

Pseudocode: user interaction loop with a menu

A menu loop: repeat shows the menu, reads the choice, picks an action with if or else if, and stops on the exit choice. Any other value gets an invalid choice message.

Understanding Pseudocode: user interaction loop with a menu in QCE Digital Solutions Unit 2

What it does: The input keyword reads the choice inside the loop each time the menu is shown, so a new value is tested on every pass. else if chains the menu options together so only the action for the matching choice runs. Repeat-until keeps looping until its condition is true. 'choice = 4' becomes true only when the user picks Exit. 'choice <> 4' would end the loop on any other choice.

Common mistakes: The menu loop must read the user's choice with input choice. print choice only displays a value that was never entered, so the if and the until have nothing to test. Line 2 should be input choice. The menu says Exit is option 3, but the loop ends on choice = 2. The menu text must match the exit choice. Line 2 should print "1 Add 2 Exit".

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 234–285) and word search (Modules 234–409).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
Which loop is the best fit for a menu that must show at least once and keep going until the user picks Exit?
repeat ... until choice = 4for i from 1 to 4
Matches
repeat print "1 Add 2 View 3 Exit" input choice ... until choice = 4
↓
The menu offers 3 as the exit option but the loop ends on 4, so choosing Exit never stops the loop. The until condition must be choice = 3.
Applying
Meanings
Term
repeat ... until choice = 4
Meaning
A menu loop: repeat shows the menu, reads the choice, picks an action with if or else if, and stops on the exit choice. Any other value gets an invalid choice message.
Practice
repeat
Testing
Gaps
Check Answer
Spots
1repeat
2 print choice

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Blobfish' badge — Pressure Handler, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. Which loop is the best fit for a menu that must show at least once and keep going until the user picks Exit?
A. repeat ... until choice = 4 ✓
B. for i from 1 to 4
A repeat-until loop always runs once, so the menu is shown first. It then stops when the exit choice is entered. A for loop runs a fixed number of times, which doesn't suit a menu.
2. In a menu loop, where should the line that reads the user's choice go?
A. Before the loop only, once at the start
B. Inside the loop, after the menu is printed ✓
The choice must be read on every pass. If you read it only once before the loop, the user can never change it and the loop will never end.
3. Which pseudocode reads the choice correctly, with the menu shown on each pass?
A. repeat print menu input choice ✓
B. input choice repeat print menu
The menu and the input both belong inside the repeat block. That way the user sees the options and chooses again on every pass.
4. A menu has options 1, 2 and 3, and 4 is Exit. What should the program do if the user types 7?
A. Print an invalid choice message and show the menu again ✓
B. Stop the loop because the choice isn't 1, 2 or 3
Only the exit choice (4) ends the loop. Any other unknown value gets an invalid choice message, and then the menu is shown again.
5. Which part of the menu structure handles the invalid choice message?
A. The until condition at the end of the loop
B. The final else after the else if options ✓
The else catches every value not matched by an earlier option. The until condition only decides when the loop stops.

Match the Pairs

repeat ... until choice = 4 → Keeps showing the menu and acting on the choice until the user picks 4, the exit option
else print "Invalid choice" → Tells the user their entry is not a menu option, then the loop shows the menu again
Each pass of the loop reads the user's menu choice so the program can select an action → input choice
A second menu option is checked with else if after the first option's if → else if choice = 2 then
repeat print "1 Add 2 View 3 Exit" input choice ... until choice = 4 → The menu offers 3 as the exit option but the loop ends on 4, so choosing Exit never stops the loop. The until condition must be choice = 3.
repeat input choice print "Choose 1, 2 or 3" if choice = 1 then ... → The menu is printed after the choice is read, so the user is asked for input before seeing the options. print the menu first, then input choice.

Key Term

repeat ... until choice = 4
A menu loop: repeat shows the menu, reads the choice, picks an action with if or else if, and stops on the exit choice. Any other value gets an invalid choice message.

Fill in the Blanks

1. repeat print "1 Play 2 Scores 3 Help 4 Exit" input choice
Hint: Type the keyword that starts a loop which always runs its body at least once, so the menu shows first.
2. print "Enter your choice:" input choice if choice = 1 then
Hint: Type the keyword that reads the user's menu choice into the variable.
3. if choice = 1 then print "Starting game" else if choice = 2 then
Hint: Type the keyword that follows else to test another menu option in a chain.
4. print "Help" else print "Invalid choice"
Hint: Type the keyword that catches every value that did not match a menu option.
5. print "4 = Exit" input choice until choice = 4
Hint: Type the menu number of the exit option, which ends the loop.

Spot the Error

Question 1
A repeat
B print choice
C if choice = 1 then
D print "Playing"
E end if
F until choice = 2
Line B — The menu loop must read the user's choice with input choice. print choice only displays a value that was never entered, so the if and the until have nothing to test. Line 2 should be input choice.
Question 2
A repeat
B print "1 Add 3 Exit"
C input choice
D until choice = 2
Line B — The menu says Exit is option 3, but the loop ends on choice = 2. The menu text must match the exit choice. Line 2 should print "1 Add 2 Exit".
Question 3
A repeat
B print "1 Play 2 Quit"
C input choice
D until choice <> 2
Line D — A menu loop must stop when the user picks the exit choice. until choice <> 2 stops on any other choice and keeps looping on Quit. It should be until choice = 2.
Question 4
A repeat
B input choice
C if choice > 4 then
D print "Valid choice"
E end if
F until choice = 4
Line D — This branch runs when the choice is not a menu option, so it must tell the user the choice is invalid. It should print "Invalid choice".
Question 5
A repeat
B input choice
C if choice = 2
D print "Viewing"
E end if
F until choice = 3
Line C — An if statement in pseudocode needs the keyword then at the end of the condition. Line 3 should be if choice = 2 then.

Student with a class code? Join your class →