These worksheets are free forever. Want lessons that adapt to your child as they learn, plus progress tracking? Try Ignition Learning free.

Sign up free

Ignition Learning — Activity Sheet

Writing better programs: control structures & debugging

Technologies · Year 7

Name: ______________________Date: ____________

Beyond simple sequences and loops, programs often need to make decisions — using control structures like "if/else" statements to run different code depending on a condition, and loops that can be nested (placed inside each other) to handle more complex, repeated logic. Before writing code, programmers often plan algorithms using flowcharts (a visual diagram of steps and decisions) or pseudocode (a plain-language outline of the logic, not tied to a specific programming language). Tracing an algorithm means manually following it step by step with a specific input, to predict its output or spot logical errors. Debugging is the process of finding and fixing errors (bugs) in a program, often by testing with different inputs and carefully checking each step.

Example

A simple game might use an "if" statement to check if a player's score is high enough to win ("if score >= 100, then display 'You win!'"), nested inside a loop that keeps checking the score every turn until the game ends.

Key terms

Control structure:
A programming feature, like "if/else" or a loop, that controls the order code runs in.
Pseudocode:
A plain-language outline of a program's logic, not written in an actual programming language.
Debugging:
Finding and fixing errors in a program.

Questions

  1. 1. A control structure:

    • Has no effect on a program
    • Controls the order code runs in, like "if/else" or loops
    • Is unrelated to programming
    • Always runs code in the same fixed order
  2. 2. An "if/else" statement:

    • Repeats code forever
    • Runs different code depending on a condition
    • Deletes code
    • Has no logical function
  3. 3. A nested loop is:

    • A single loop only
    • A loop placed inside another loop
    • Not a real programming concept
    • Always an error
  4. 4. Pseudocode is:

    • Actual running code
    • A plain-language outline of a program's logic
    • A type of hardware
    • Unrelated to programming
  5. 5. A flowchart is:

    • A type of error
    • A visual diagram of steps and decisions
    • Unrelated to planning code
    • Always incorrect
  6. 6. To trace an algorithm means to:

    • Ignore it
    • Manually follow it step by step to predict its output
    • Delete it
    • Run it randomly
  7. 7. Debugging means:

    • Adding more errors
    • Finding and fixing errors in a program
    • Ignoring all errors
    • Deleting the whole program
  8. 8. An "if score >= 100, then display 'You win!'" statement is an example of:

    • A loop only
    • A control structure making a decision based on a condition
    • Unrelated to programming
    • A type of hardware
  9. 9. Why might a programmer use pseudocode before writing actual code?

    • Pseudocode has no purpose
    • To plan the logic clearly without worrying about specific programming syntax yet
    • Pseudocode replaces the need for real code entirely
    • It only wastes time
  10. 10. Nesting a loop inside another loop is useful when:

    • Never useful
    • You need to repeat an action multiple times within another repeating process
    • Loops can never be combined
    • It always causes errors
  11. 11. Tracing an algorithm with a specific test input mainly helps:

    • Confuse the programmer
    • Predict the output and check for logical errors
    • Automatically fix all bugs
    • Replace the need for testing
  12. 12. If a program produces unexpected output, a programmer should:

    • Ignore the issue
    • Debug it by tracing the logic and testing different inputs
    • Delete the whole program immediately
    • Assume it's correct anyway
  13. 13. A flowchart showing a decision point (like a diamond shape with "yes/no") represents:

    • A loop only
    • A control structure making a choice
    • Unrelated content
    • An error in the program
  14. 14. Why might testing a program with multiple different inputs help with debugging?

    • Testing has no value
    • Different inputs can reveal errors that a single test case might miss
    • One test is always sufficient
    • More testing always causes more bugs
  15. 15. A program using a nested loop to check every student against every possible grade produces incorrect results. What debugging approach would help most?

    • Ignoring the problem
    • Tracing through the nested loop step by step with sample data to find where the logic breaks down
    • Deleting the loops without understanding the issue
    • Assuming the computer is broken
  16. 16. Why might planning an algorithm with pseudocode before coding help avoid certain types of errors?

    • Pseudocode introduces more errors
    • Clarifying the logic first can catch flawed reasoning before it is implemented in code
    • Skipping planning always leads to fewer errors
    • Pseudocode has no relationship to actual code quality
  17. 17. A program's "if/else" statement always executes the "if" branch, even when the condition should be false. What might this suggest to a debugger?

    • Nothing is wrong, this is expected
    • There may be a logical error in how the condition is written or evaluated
    • "If" statements never contain errors
    • The program is functioning perfectly
  18. 18. Why might a nested control structure be more error-prone than a simple, single structure?

    • Nested structures are always simpler
    • Additional layers of logic increase the number of places an error could occur
    • Nesting removes all possible errors
    • Complexity has no relationship to error likelihood
  19. 19. Which best demonstrates good debugging practice?

    • Randomly changing code until it works by chance
    • Systematically tracing logic, testing inputs, and identifying exactly where behaviour differs from expectations
    • Ignoring errors and hoping they resolve themselves
    • Rewriting the entire program from scratch every time
  20. 20. Understanding control structures, planning tools and debugging mainly helps students:

    • Write programs randomly with no logical structure
    • Design, plan and troubleshoot more complex program logic effectively
    • Avoid ever testing their code
    • Skip planning before writing programs

Answer key (parent copy)

  1. 1. Controls the order code runs in, like "if/else" or loops
  2. 2. Runs different code depending on a condition
  3. 3. A loop placed inside another loop
  4. 4. A plain-language outline of a program's logic
  5. 5. A visual diagram of steps and decisions
  6. 6. Manually follow it step by step to predict its output
  7. 7. Finding and fixing errors in a program
  8. 8. A control structure making a decision based on a condition
  9. 9. To plan the logic clearly without worrying about specific programming syntax yet
  10. 10. You need to repeat an action multiple times within another repeating process
  11. 11. Predict the output and check for logical errors
  12. 12. Debug it by tracing the logic and testing different inputs
  13. 13. A control structure making a choice
  14. 14. Different inputs can reveal errors that a single test case might miss
  15. 15. Tracing through the nested loop step by step with sample data to find where the logic breaks down
  16. 16. Clarifying the logic first can catch flawed reasoning before it is implemented in code
  17. 17. There may be a logical error in how the condition is written or evaluated
  18. 18. Additional layers of logic increase the number of places an error could occur
  19. 19. Systematically tracing logic, testing inputs, and identifying exactly where behaviour differs from expectations
  20. 20. Design, plan and troubleshoot more complex program logic effectively