Day 9 - Iteration (Loops) - Part 2

Day 9: Iteration (Loops) - Part 2

Learning Objectives

Essential Questions

Materials Needed

Vocabulary

Procedure (50 minutes)

Opening (8 minutes)

  1. Review and Connection (3 minutes)

    • Review count-controlled loops from previous lesson
    • Connect to today's focus on condition-controlled loops
  2. Warm-up Activity (5 minutes)

    • Present a scenario where the number of repetitions is not known in advance (e.g., keep asking for input until a valid value is entered)
    • Ask students how they might approach this with what they know so far
    • Introduce the need for loops that run until a condition is met

Main Activities (32 minutes)

  1. Lecture: Condition-controlled Loops (While Loops) (12 minutes)

    • Introduce condition-controlled loops (while loops):
      • Structure and syntax: REPEAT UNTIL(condition)
      • How the loop condition works
      • Execution flow in a condition-controlled loop
      • When to use condition-controlled loops
    • Explain that the loop continues until the condition becomes true
    • Discuss the concept of pre-test loops (condition checked before execution)
    • Explain common patterns and use cases for while loops:
      • Processing input until a sentinel value
      • Finding values that meet certain criteria
      • Implementing algorithms with unknown iterations
    • Discuss infinite loops and how to avoid them
    • Explain the importance of ensuring the loop condition will eventually be true
  2. Demo: Implementing While Loops in Code (8 minutes)

    • Walk through examples of programs with while loops:
      • Validating user input
      • Finding the first number that meets a condition
      • Implementing a guessing game
      • Processing data until a threshold is reached
    • Show how to trace the execution of while loops step by step
    • Demonstrate how the loop condition is evaluated each time
    • Highlight common patterns and techniques with while loops
    • Show examples of infinite loops and how to fix them
  3. Hands-on: Converting Between Loop Types (12 minutes)

    • Students work in the programming environment
    • Guide students through converting between for loops and while loops
    • Have students implement the same task using both loop types
    • Discuss when each type is more appropriate
    • Have students identify scenarios where one loop type is clearly better than the other
    • Encourage students to trace their loops manually to understand execution flow

Closing (10 minutes)

  1. Activity: Solving Problems with Appropriate Loop Structures (5 minutes)

    • Provide students with various problem scenarios
    • Students determine which loop structure is most appropriate for each scenario
    • Implement one of the scenarios using the chosen loop structure
    • Share and discuss different approaches
    • Highlight the decision-making process for choosing loop types
  2. Exit Ticket and Preview (5 minutes)

    • Students create a program that uses the appropriate loop structure for a given problem
    • Preview that next class will focus on nested control structures

Assessment

Differentiation

For Advanced Students

For Struggling Students

Homework/Extension

Teacher Notes