Skip to content

How Decisions Affect Program Flow

2.1.4 Thinking logically · Paper 2 · 7 flashcards · 4 questions

Definition
The decisions made during design and development have a direct impact on program flow. Each decision shapes how the program operates, leading to different paths and outcomes.
Worked Example
Worked Example: Game Design Decisions

Scenario: designing a runner game.
Design choiceOptionProgram-flow impact
Game typeEndless runnerSingle continuous loop; no level-save transitions
Game typeLevel-basedLevel loading, progress tracking, save/load logic
pseudocode
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
Each user choice sends control flow down a different branch.
Key Point
Planning pointGood practice
Unexpected user inputInclude explicit else/validation branches
Multiple valid choicesHandle each branch deliberately
Error preventionProvide clear fallback/error path
pseudocode
// 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 madeEffect on the flow of the program
if / elseif / elseOne block of code is run and the others are skipped; execution then continues after the end of the if statement
switch / caseThe value of one variable selects which block is run
while loopThe condition is tested before each pass; when it is false the loop is skipped or ends
do-until loopThe condition is tested after each pass, so the code inside always runs at least once
Nested ifThe inner condition is only tested when the outer condition has already given a particular result
Worked Example
Tracing How Decisions Change the Flow
pseudocode
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 enteredLines run, in orderOutput
open01, 02, 03, 07, 08Access granted
cat, open01, 02, 03, 04, 05, 03, 07, 08Access granted
cat, dog, pig01, 02, 03, 04, 05, 03, 04, 05, 03, 07, 09, 10Account locked
The same code follows three different routes, because the conditions on lines 03 and 07 give different results for different inputs.
Exam Tip
Exam Tips for Thinking Logically:
• 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