Home›Lesson Plans›Computer Science›Programming · Grade 9

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 perfect for grids, tables, and patterns. They check the ideas, then trace a nested loop.

Grade 9Nested Loops55 minutes1 class periodCSTA / ISTEExplicit teaching4 StandardsCSTA
Start the Lesson
Assign or share this lesson

Copy link works with Canvas, Schoology, Moodle and any other LMS — paste it in as a resource or assignment.

Lesson at a Glance

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.
Essential Question

What happens when you put one loop inside another?

0
Lesson Phases
0
Vocabulary Terms
0
Standards Aligned
0
Interactive Task
Check It · Interactive

Nested Loops

Project each one and have students answer about nested loops.

🔁 Understand nested loopsTry it
Answer each question about nested loops.
The Lesson · Explicit teaching

55 minutes, five moves

Tap any phase to open the teacher moves and student actions.

1

Hook — Loops in Loops

6 min

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.
2

Use — Nested Loops

13 min

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.
3

Modify — Trace It

14 min

Students practice.

👩‍🏫 Teacher Moves

  • Trace a small nested loop.
  • Count total iterations.
  • Predict the output.

🎒 Student Actions

  • Trace.
  • Count.
  • Predict.
4

Create — Create

15 min

Students apply.

👩‍🏫 Teacher Moves

  • Write a nested loop.
  • Make it draw a grid.
  • Test the output.

🎒 Student Actions

  • Write.
  • Grid.
  • Test.
5

Reflect — Reflect

7 min

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.
Standards Alignment

Built to the standards you report on

Aligned to the CSTA K-12 Computer Science Standards and the ISTE Standards for Students.

CSTA
3A-AP-14

Use nested control structures.

CSTA
3A-AP-15

Justify the choice of control structures.

CSTA
3A-AP-17

Test and debug loops.

ISTE
5c

Reason about repetition and scale.

Differentiation

One lesson, every learner

Multilingual Learners

ELL / EMERGING READERS
  • Grid/loop diagrams.
  • Frame: "the inner loop runs ___ times."
  • Trace a tiny grid.

Support & Access

IEP / 504
  • Use a 2×2 grid.
  • Trace slowly.
  • Use a visual.

Stretch & Extend

GIFTED / EARLY FINISHERS
  • Nest three loops.
  • Draw a multiplication table.
  • Analyze loop efficiency.
Materials

What to gather

  • 📽️Screen / board
  • 🔁Loop diagram
  • 💻Nested Loops
  • 📋Trace worksheet
  • 📓Notebooks
  • 🎫Exit-ticket slips
Vocabulary

Key terms — hover for a quick definition

nested loopa loop inside another loopouter loopthe loop on the outsideinner loopthe loop insideiterationone pass of a loopgridrows and columnsindexa loop counterbodythe code a loop repeatstracefollow the code by hand
Evaluate

Exit Ticket

Preview the three formative checks. Tap “Sample answer” to see what mastery looks like — hide them before you print for students.

QUESTION 1
What is a nested loop?
A loop placed inside another loop.
QUESTION 2
If outer runs 3 and inner runs 4, how many inner runs total?
12 (3 × 4).
QUESTION 3
What are nested loops great for?
Grids, tables, and rows-and-columns problems.

Reflect: nested loops.

Have students write a nested loop that draws a grid. A printable trace worksheet is in the CS library.

Study · Flashcards

Study the key terms

Tap a card to flip it, then rate whether you knew it. Built from this lesson’s vocabulary.

🃏 Nested LoopsFlip
Card 1
Term
Tap to flip →
Meaning
0

Nice work!

Practice · Quiz

Check your understanding

A quick self-check with instant feedback, drawn from this lesson’s key terms.

📝 Nested LoopsQuiz
Score: 0
1 / 6
Question 1
0%

Nice work!

Practice · Worksheet

Printable worksheet

A print-and-go review sheet with a built-in answer key. Tap “Show answer key” to reveal answers, or print the clean version for students.

🖨️ Nested LoopsPrint
Name: ________________________
Date: ____________

Part A · Write the word that matches each meaning

Word bank: body, grid, index, inner loop, iteration, nested loop, outer loop, trace
  1. follow the code by hand
  2. one pass of a loop
  3. rows and columns
  4. the loop on the outside
  5. a loop inside another loop
  6. the code a loop repeats
  7. a loop counter
  8. the loop inside

Part B · Show what you learned

  1. What is a nested loop?
  2. If outer runs 3 and inner runs 4, how many inner runs total?
  3. What are nested loops great for?
Answer key — Part A: 1) trace · 2) iteration · 3) grid · 4) outer loop · 5) nested loop · 6) body · 7) index · 8) inner loop
Part B: 1) A loop placed inside another loop. 2) 12 (3 × 4). 3) Grids, tables, and rows-and-columns problems.