# Nested Loops > Ninth graders learn nested loops — a loop inside another loop. The inner loop runs completely for every pass of the outer loop, which makes nested loops… **Computer Science** | **Grade 9** *A free lesson plan from K12 Academics. Source page: https://lessonplans.k12academics.com/k12-lesson-g9-cs-nested-loops.html* Ninth graders learn nested loops — a loop inside another loop. The inner loop runs completely for every pass of the outer loop, which makes nested loops perfect for grids, tables, and patterns. They check the ideas, then trace a nested loop. **Copy link** works with Canvas, Schoology, Moodle and any other LMS — paste it in as a resource or assignment. ## Everything you need before the bell rings ### Learning Objectives Students will be able to… - Define a **nested loop**. - Count the **iterations**. - Use it for **grids**. - Trace the output. What happens when you put one loop inside another? Project each one and have students answer about nested loops. ## 55 minutes, five moves Tap any phase to open the teacher moves and student actions. ### Hook — Loops in Loops How would you print a 3-by-4 grid of stars with loops? #### 👩‍🏫 Teacher Moves - Pose the question. - Share ideas. - Set the goal. #### 🎒 Student Actions - Think. - Share. - Get ready. ### Use — Nested Loops Students learn. #### 👩‍🏫 Teacher Moves - Send students to Nested Loops. - Note inner runs fully each pass. - Note 3×4 = 12. #### 🎒 Student Actions - Answer. - Note it. - Note it. ### Modify — Trace It Students practice. #### 👩‍🏫 Teacher Moves - Trace a small nested loop. - Count total iterations. - Predict the output. #### 🎒 Student Actions - Trace. - Count. - Predict. ### Create — Create Students apply. #### 👩‍🏫 Teacher Moves - Write a nested loop. - Make it draw a grid. - Test the output. #### 🎒 Student Actions - Write. - Grid. - Test. ### Reflect — Reflect Students close. #### 👩‍🏫 Teacher Moves - What is a nested loop? - How many runs for 2×5? - Complete the exit ticket. #### 🎒 Student Actions - Say it. - Say it. - Complete the exit ticket. ## Built to the standards you report on Aligned to the CSTA K-12 Computer Science Standards and the ISTE Standards for Students. Use nested control structures. Justify the choice of control structures. Test and debug loops. Reason about repetition and scale. ## One lesson, every learner ### Multilingual Learners - Grid/loop diagrams. - Frame: "the inner loop runs ___ times." - Trace a tiny grid. ### Support & Access - Use a 2×2 grid. - Trace slowly. - Use a visual. ### Stretch & Extend - Nest three loops. - Draw a multiplication table. - Analyze loop efficiency. ### What to gather - 📽️Screen / board - 🔁Loop diagram - 💻Nested Loops - 📋Trace worksheet - 📓Notebooks - 🎫Exit-ticket slips ### Key terms - **nested loop**: a loop inside another loop - **outer loop**: the loop on the outside - **inner loop**: the loop inside - **iteration**: one pass of a loop - **grid**: rows and columns - **index**: a loop counter - **body**: the code a loop repeats - **trace**: follow the code by hand ## Exit Ticket Preview the three formative checks. Tap “Sample answer” to see what mastery looks like — hide them before you print for students. ### Reflect: nested loops. Have students write a nested loop that draws a grid. A printable trace worksheet is in the CS library. ## Check your understanding **1. What does “nested loop” mean?** - the loop inside - the code a loop repeats - a loop inside another loop *(correct)* - a loop counter “nested loop” means: a loop inside another loop **2. Which word means: “the loop on the outside”?** - outer loop *(correct)* - index - grid - inner loop “outer loop” means: the loop on the outside **3. What does “inner loop” mean?** - a loop inside another loop - the loop inside *(correct)* - rows and columns - follow the code by hand “inner loop” means: the loop inside **4. Which word means: “one pass of a loop”?** - body - outer loop - iteration *(correct)* - trace “iteration” means: one pass of a loop **5. What does “grid” mean?** - the code a loop repeats - a loop counter - one pass of a loop - rows and columns *(correct)* “grid” means: rows and columns **6. Which word means: “a loop counter”?** - body - index *(correct)* - iteration - trace “index” means: a loop counter ## Printable worksheet --- Full lesson page: https://lessonplans.k12academics.com/k12-lesson-g9-cs-nested-loops.html All lessons: https://lessonplans.k12academics.com/