Day 9 - Iteration (Loops) - Part 2
Day 9: Iteration (Loops) - Part 2
Learning Objectives
- AAP-2.H: For iteration: Write iteration statements.
- AAP-2.I: For iteration: Determine the result or side effect of iteration statements.
- AAP-2.J: Express an algorithm that uses iteration without using a programming language.
- AAP-2.K: For iteration: Determine the result or side effect of iteration statements.
Essential Questions
- When should we use condition-controlled loops instead of count-controlled loops?
- How do we design loops that continue until a specific condition is met?
Materials Needed
- Presentation slides on condition-controlled loops
- Programming environment
- Loop conversion worksheet
- Problem-solving scenarios for loops
- Exit ticket templates
Vocabulary
- Condition-controlled loop
- While loop
- REPEAT UNTIL
- Loop condition
- Termination condition
- Infinite loop
- Pre-test loop
- Iteration
Procedure (50 minutes)
Opening (8 minutes)
-
Review and Connection (3 minutes)
- Review count-controlled loops from previous lesson
- Connect to today's focus on condition-controlled loops
-
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)
-
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
- Introduce condition-controlled loops (while loops):
-
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
- Walk through examples of programs with while loops:
-
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)
-
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
-
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
- Formative: Quality of loop implementation and conversion during hands-on activities
- Exit Ticket: Correctness of loop structure choice and implementation
Differentiation
For Advanced Students
- Provide more complex looping challenges
- Introduce do-while loop concept (post-test loop)
- Challenge them to implement algorithms requiring sophisticated loop control
For Struggling Students
- Offer more structured templates for while loops
- Provide step-by-step tracing guides
- Focus on clear termination conditions to avoid infinite loops
Homework/Extension
- Complete a worksheet with while loop exercises
- Create a program that uses both for loops and while loops appropriately
- Research real-world algorithms that use condition-controlled loops
Teacher Notes
- Emphasize the difference between count-controlled and condition-controlled loops
- Watch for infinite loops in student code
- Make connections to real-world scenarios where the number of repetitions is unknown
- Consider using analogies like "keep stirring until the mixture thickens"
- Remind students that choosing the right loop structure makes code more readable and efficient