Scenario: designing a runner game.
| Design choice | Option | Program-flow impact |
|---|---|---|
| Game type | Endless runner | Single continuous loop; no level-save transitions |
| Game type | Level-based | Level loading, progress tracking, save/load logic |
procedure gameLoop():
displayOptions(["Run", "Jump", "Slide"])
choice = getUserInput()
if choice == "Run" then
moveCharacterForward()
elseif choice == "Jump" then
jumpOverObstacle()
elseif choice == "Slide" then
slideUnderBarrier()
end if
end procedure
| Planning point | Good practice |
|---|---|
| Unexpected user input | Include explicit else/validation branches |
| Multiple valid choices | Handle each branch deliberately |
| Error prevention | Provide clear fallback/error path |
// Better planning for yes/no input
if userInput == "yes" then
processOrder()
elseif userInput == "no" then
cancelOrder()
else
displayError("Please enter yes or no")
end if
Selection, Iteration and Nested Decisions
| Where the decision is made | Effect on the flow of the program |
|---|---|
| if / elseif / else | One block of code is run and the others are skipped; execution then continues after the end of the if statement |
| switch / case | The value of one variable selects which block is run |
| while loop | The condition is tested before each pass; when it is false the loop is skipped or ends |
| do-until loop | The condition is tested after each pass, so the code inside always runs at least once |
| Nested if | The inner condition is only tested when the outer condition has already given a particular result |
01 attempts = 0
02 password = input("Password")
03 while password != "open" AND attempts < 2:
04 attempts = attempts + 1
05 password = input("Password")
06 end while
07 if password == "open" then
08 print("Access granted")
09 else
10 print("Account locked")
11 end if
| Passwords entered | Lines run, in order | Output |
|---|---|---|
| open | 01, 02, 03, 07, 08 | Access granted |
| cat, open | 01, 02, 03, 04, 05, 03, 07, 08 | Access granted |
| cat, dog, pig | 01, 02, 03, 04, 05, 03, 04, 05, 03, 07, 09, 10 | Account locked |
• Identify every decision point in a given scenario: each place where the solution could do one of two things
• Write the condition tested at each one exactly, using comparison and Boolean operators
• Check the boundary values of each condition
• Follow each route through the code for different inputs to show how the decisions affect program flow