Lesson 11: Nested Loops in Maze
55 minutes
Overview
In this skill-building lesson, students will learn how to program a loop inside of another loop.
Purpose
In this introduction to nested loops, students will go outside of their comfort zone to create more efficient solutions to puzzles.
In earlier puzzles, loops pushed students to recognize repetition. Here, students will learn to recognize patterns within repeated patterns to develop these nested loops. This stage starts off by encouraging students to try to solve a puzzle where the code is irritating and too complex to write out the long way. After a video introduces nested loops, students are shown an example and asked to predict what will happen when a loop is put inside of another loop. This progression leads to plenty of practice for students to solidify and build on their understanding of looping in programming.
Standards
AP - Algorithms & Programming
- 1B-AP-11 - Decompose (break down) problems into smaller, manageable subproblems to facilitate the program development process.
- 1B-AP-12 - Modify, remix or incorporate portions of an existing program into one's own work, to develop something new or add more advanced features.
- 1B-AP-15 - Test and debug (identify and fix errors) a program or algorithm to ensure it runs as intended.
Agenda
Objectives
Students will be able to:
- Break complex tasks into smaller repeatable sections.
- Identify the benefits of using a loop structure instead of manual repetition.
- Recognize large repeated patterns as made from smaller repeated patterns.
Preparation
- Play through the puzzles to find any potential problem areas for your class.
Links
Heads Up! Please make a copy of any documents you plan to share with students.
For the teachers
- CSF - Course D - Slides 2022-2023 - Slides (Download)
Vocabulary
- Command - An instruction for the computer. Many commands put together make up algorithms and computer programs.
- Loop - The action of doing something over and over again.
- Repeat - To do something again.
Teaching Guide
Warm Up (10 minutes)
Introduction
Display: Show “Reflect” slide
Briefly review with the class what loops are and why we use them.
- What do loops do?
- Loops repeat a set of commands.
- How do we use loops?
- We use loops to create a pattern made of repeated actions.
Display: Show “Looping a Loop” slide
Tell the class that they will now be doing something super cool: using loops inside loops.
Say: Can you predict what kinds of things we would be using a loop inside of a loop for?
If a loop repeats a pattern, then looping a loop would repeat a pattern of patterns!
Students don't need to understand this right away, so feel free to move on to the online puzzles even if students still seem a little confused.
Vocabulary
Display: Show “Vocabulary” slide
-
Command - An instruction for the computer.
-
Loop - The action of doing something over and over again.
-
Repeat - To do something again.
Main Activity (30 minutes)
Nested Loops in Maze
We highly recommend pair programming for this lesson. This may not be an easy topic for the majority of your students. Working with a partner and discussing potential solutions to the puzzles might ease the students' minds.
Also, have paper and pencils nearby for students to write out their plan before coding. Some puzzles have a limit on the number of certain blocks you can use, so if students like to write out the long answer to find the repeats, paper can be useful.
Display: Show “Level 1-2 - Skill Building” slide
Display: Show “Nested Loops with Bee” video
Display: Show “Level 4 - Predict” slide
Display: Show “Level 5-9 - Skill Building” slide
Display: Show “Level 11-12 - Practice” slide
Display: Show “Level 13 - Predict” slide
Lesson Extras
Display: Show “Lesson Extras” slide
Wrap Up (15 minutes)
Reflection
Display: Show “Reflect” slide
Reflect:
-
Draw a puzzle that would use a nested loop.
-
Try coding the solution to your own puzzle.
This work is available under a Creative Commons License (CC BY-NC-SA 4.0).
If you are interested in licensing Code.org materials for commercial purposes contact us.