Nested Loops - Inner and Outer

This lesson is for more advanced students wanting to code a Python program that uses nested loops. This is not block coding. They will use their own IDE to write the program. I have attached a photo of a sample program that they can write.

Author: Selena Pope
Grade Level: 9-12
Standard Framework: Wyoming CS
Standards: Wyoming BootUp L1.AP.C.01, L2. AP.C.01, L1.AP.C.02
Materials: Raspberry Pi, Python friendly IDE

OVERVIEW

Activity Overview:

This lesson is for more advanced students wanting to code a Python program that uses nested loops. This is not block coding. They will use their own IDE to write the program. I have attached a photo of a sample program that they can write.

Meta description

  • Subject Area: Programming Logic and Design - Python
  • Grade Level : 9-12
  • Computer Science Domains:
    • Algorithms and Programming
  • Computer Science Principles:
    • Recognizing and Defining Computational Problems, Creating Computational Artifacts
  • Materials:
    • Raspberry Pi, Python friendly IDE
  • Considerations:
    • Students and/or teachers need their own IDE if you want them to build their own programs.

Lesson Plan

Overview

This lesson is for more advanced students wanting to code a Python program that uses nested loops. This is not block coding. They will use their own IDE to write the program. I have attached a photo of a sample program that they can write.

ASSESSMENT PRE/POST-TEST

What is a nested loop? Why would we need a nested loop?

OBJECTIVES

Students will be able to explain what a nested loop is and demonstrate how they can be used in a program.

CATCH/HOOK

https://www.youtube.com/watch?v=O60CFmcWyEY

ACTIVITY INSTRUCTIONS

Vocabulary: nested loop, inner loop, outer loop

Key ideas: Nested loops never overlap. Ann inner loop is always completely contained within an outer loop.

An inner loop goes through all of its iterations each time as the outer loop goes through just one.

The total number of iterations executed by a nested loop is the number of inner loop iterations times the number of outer loop iterations.

Write the program. Allow students to follow along or give it a go on their own. Debug together as a class as problems arise.

Supplements

Any items in this section are the property & under the license of their respective owners.

REVIEW

Play 2 truths and a lie. Which 2 are true? When one loop is nested inside another, the loop that contains the other loop is called the outer loop.

You need to create nested loops when the values of two or more variables repeat to produce every combination of values.

The number of times a loop executes always depends on a constant.

STANDARDS

TypeListing
CS DomainsAlgorithms and Programming
CS PrinciplesRecognizing and Defining Computational Problems, Creating Computational Artifacts
Other Content StandardsWyoming BootUp L1.AP.C.01, L2. AP.C.01, L1.AP.C.02