Cover Page

Code Jumper Curriculum: Lessons, Lesson 14 Nested Loops

American Printing House for the Blind

Code Jumper Curriculum: Lessons

Copyright © 2020 American Printing House for the Blind

All rights reserved. No part of this publication may be reproduced, stored in retrieval system, or transmitted in any form or by any means, except as expressly permitted under copyright law, without written permission of the publisher.

Published by American Printing House for the Blind

1839 Frankfort Avenue, Louisville, KY 40206

www.aph.org | [email protected]

Overview

Lesson Objectives

Students will:

  • Understand what a nested loop is and be able to develop programs that use nested loops.

Expected Outcomes

Students will:

  • All students: Be able to state that a nested loop is a loop inside another loop
  • Most students: Be able to create a program that uses nested loops
  • Some students: Be able to create a program that uses nested loops and counters

Lesson Plan Structure

  • Unplugged Activity
  • Guided Code Jumper Activity
  • Exploration
  • Standards and Check for Understanding

Key Vocabulary

  • Loop: A way to organize commands in a computer program so they repeat a sequence of instructions or actions a required number of times.
  • Nested Loop: A loop within another loop, where the entire sequence of instructions/actions is repeated.

Unplugged Activity

Objective

After this lesson, students will understand the concept of a loop and how computer programs use nested loops.

Overview

In this lesson, students will identify real-world examples of nested loops and choose one of the examples to record in their Computer Science Journals for future reference.

Materials

Computer Science Journal: Nested Loops (example at the end of lesson)

Instructions

  1. Ask students to brainstorm as a class some ideas of things that repeat over and over:
    • The minute or second hand on a clock
    • The Earth rotating around the sun
    • A stopwatch
    • Songs
      • Refrain
      • Chorus
      • Refrain
      • Chorus
  2. Explain to students that something like the second hand on a clock is the same concept of a loop in computer programming. It repeats the same action over and over.
  3. Discuss with students that a nested loop in computer programming is where one loop is inside another loop. Ask them to think of their brainstormed examples and see if any of them could be considered a nested loop:
    • Clock: The second hand repeats every 60 seconds and then the minute hand moves to the next minute
    • Earth: Rotates itself as it also moves around the sun
    • Stopwatch: Counts the seconds and after 60 seconds the minutes begin to count up
  4. Tell students to choose one of the examples they talked about in class as a way to remember how a nested loop works and to write the name of the example on the lines provided. (See Nest Loops Computer Science Journal Print Example at the end of the lesson.)
  5. Once the students have written their example in their journal, have students choose a picture icon (see examples at the end of the lesson) representing that example and glue it in the box on that page. Adapt materials as necessary prior to lesson.
  6. Tell students that they will be using Code Jumper to create programs with nested loops.

Code Jumper Guided Activity

Objective

  • Students will be able to develop programs that use nested loops
  • Students will create a program using nested loops

Materials

  • Code Jumper Kit
  • Hub
  • Play pods
  • Loop pods
  • Extension cord
  • Nested Loop Code Card 1: Count the Notes
  • Nested Loop Code Card 2: With Melody

Instruction

Remind students that a nested loop is a loop inside a loop. What does that mean? It means that we have two Loop pods telling us to repeat a part of the program a certain number of times. The inside loop may be configured to play two Play pods three times, and the outer loop then tells the program to play the inside loop four times. This means that the inner loop plays the two sounds three times for a total of six sounds, and those sounds are then played four times. The program will play a total of 24 sounds: (2 x 3) 4 = 24. Each sound will play 12 times.

  1. Distribute the Nested Loop Code Card 1: Count the Notes to students. Have students pair up to decode the program. In their Computer Science Journals, have students determine how many sounds total should be played, and how many of each sound.
  2. Ask students to get out the extension cord and explain that when creating Nested loops, the cords may not be long enough. The extension cord can be plugged into the Loop pod and Command pod to close the loop.

    A photo of a Code Jumper program for a nested loop that incorporates the extension cord.

    [Figure Caption:] This is a photo of a Code Jumper program for a nested loop that incorporates the extension cord. A Loop pod is connected to the Hub and a second Loop pod, and the second Loop pod is composed of three Play pods. The extension cord, which is connected to the second Loop pod’s upper-right port, wraps around the Play pods and then closes the loop at the first Loop pod’s longer wire.
  3. In their groups, ask students to create the program from the Nested Loops Code Card 1: Count the Notes and determine if their hypothesis was correct. Remind students to trace the code as they listen. One student can trace the code, and another can take notes or tally the number of sounds they are hearing.
  4. Have the students reflect in their Computer Science Journals if their hypothesis was correct, and if not, where the error was made.
  5. Create the program from the Nested Loop Code Card 2: With Melody. Cover it with a cloth so students can focus on the sounds.
  6. Ask students to listen to the program, determine how many sounds they are hearing, and work on decomposing the program to determine where the loops are and how many notes are being played.
  7. Ask students to try to recreate the program based on the code they wrote. (Tip! Make sure students lay out their program so the loops are placed inside each other, as this will make it easier to trace the program. This will require using the long cord that’s included in the Code Jumper kit.) This is an opportunity for trial and error, so remind students that it is not necessary to get it correct on the first try. Instead, they should try to determine where the errors are and then try again. Have the program available for students so they can listen to it multiple times.

    Tip! If you only have one kit or would like students to have the sounds on demand, either screen-record the program and send to students or play the program from your computer.

  8. When finished, instruct students to listen to the code that makes up their program by pressing the Play and Pause buttons simultaneously.
  9. Give students time to create a nested loop program on their own. Then, ask students to write the code in their Computer Science Journals.

Closure

  • Ask students to explain what a nested loop is and how they used one in their programs.
  • Ask students to explain why nested loops are useful.

Exploration

Overview

Students will create a nested loop program that contains at least 18 total sounds and uses only three Play pods.

Materials

  • Computer
  • Hub
  • 3 Play pods
  • 2 Loop pods

Setup

  1. Give students the Hub, two Loop pods, and three Play pods.
  2. Ask students to plan out an original program in their Computer Science Journals and then create the program using nested loops.
  3. Challenge students to create a program with the most sounds possible by offering a prize for the group with the longest program. The longest program will have 192 sounds!
  4. Provide an added bonus or prize for students who can trace all 192 sounds.

Closure

Ask students to reflect on their experience of creating a nested loop program in their Computer Science Journals.

Standards and Check for Understanding

CSTA K-12 Computer Science Standards*

  • 1B-AP-08: Compare and refine multiple algorithms for the same task and determine which is the most appropriate.
  • 1B-AP-10: Create programs that include sequences, events, loops, and conditionals.

National Curriculum of England**

Key Stage 1:

  • Understand what algorithms are; how they are implemented as programs on digital devices; and that programs execute by following precise and unambiguous instructions
  • Create and debug simple programs
  • Use logical reasoning to predict the behavior of simple programs
  • Use technology purposefully to create, organize, store, manipulate and retrieve digital content
  • Recognize common uses of information technology beyond school
  • Use technology safely and respectfully, keeping personal information private; identify where to go for help and support when they have concerns about content or contact on the internet or other online technologies

Key Stage 2:

  • Design, write and debug programs that accomplish specific goals, including controlling or simulating physical systems; solve problems by decomposing them into smaller parts
  • Use sequence, selection, and repetition in programs; work with variables and various forms of input and output
  • Use logical reasoning to explain how some simple algorithms work and to detect and correct errors in algorithms and programs
  • Use search technologies effectively, appreciate how results are selected and ranked, and be discerning in evaluating digital content
  • Use technology safely, respectfully and responsibly; recognize acceptable/unacceptable behavior; identify a range of ways to report concerns about content and contact.

Closing Activities and Check for Understanding

Have the students write in their Computer Science Journals why using nested loops would be helpful in creating a program.

Check for Understanding Completed
Student can create a program that incorporates a nested loop with two or more pods. Yes / No

Additional Materials

Nested Loops Computer Science Journal Print Example

__________________________________________________

__________________________________________________

__________________________________________________

__________________________________________________

Nested Loops Handout

Three images are displayed, clockwise: An analog clock, a compass, and Earth.

[Figure Caption:] Three images are displayed, clockwise: An analog clock, a compass, and Earth.

Code Cards

Nested Loop Code Card 1: Count the Notes

THREAD 2 Piano

LOOP 4 times

LOOP 3 times

PLAY E5 for 1 beat

PLAY E5 for 1 beat

END LOOP

END LOOP

END THREAD

A screenshot of a nested loop Code Jumper program in Thread 2.

A photo showing a nested loop Code Jumper program in port 2.

[Figure Caption:] At the top is a screenshot of a nested loop Code Jumper program in Thread 2. Under THREAD 2 Piano, the commands read, LOOP 4 times, LOOP 3 times, PLAY E5 for 1 beat, PLAY E5 for 1 beat, END LOOP, END LOOP. The commands are followed by END THREAD. Below the screenshot is a photo showing this same program. The first Loop pod is connected by its short wire to the Hub at Port 2. The second Loop pod is connected to the first Loop pod’s lower-right port and to an extension cord that is connected to the first Loop pod’s longer wire. The extension cord surrounds two Play pods, which are connected, one after the other, to the second Loop pod’s lower-right port and to the second Loop pod’s longer wire.

Nested Loop Code Card 2: With Melody

THREAD 1 Piano

LOOP 3 times

LOOP 3 times

PLAY C5 for a 1/4 beat

PLAY D5 for a 1/4 beat

PLAY E5 for a 1/4 beat

END LOOP

PLAY D5 for 1/2 a beat

END LOOP

END THREAD

A screenshot of a Code Jumper program in Thread 1.

A photo of a Code Jumper program in port 1.

[Figure Caption:] At the top is a screenshot of a Code Jumper program in Thread 1. Under Thread 1 Piano, the commands read, LOOP 3 times, LOOP 3 times, PLAY C5 for a 1/4 beat, PLAY D5 for a 1/4 beat, PLAY E5 for a 1/4 beat, END LOOP, PLAY D5 for 1/2 a beat, END LOOP; the commands are followed by End Thread. Below the screenshot is a photo showing this same nested loop program. The first Loop pod is connected by its short wire to the Hub at Port 1. The second Loop pod is connected to the first Loop pod’s lower-right port. A Play pod is connected to the second Loop pod’s upper-right port and to an extension cord that is connected to the first Loop pod’s longer wire. The extension cord surrounds three Play pods, which are connected, one after the other, to the second Loop pod’s lower-right port and to the second Loop pod’s longer wire.

A screenshot of a nested loop Code Jumper program in Thread 2.

Code Jumper

For more resources, visit codejumper.com

Copyright © 2020

American Printing House

1839 Frankfort Avenue

Louisville, Kentucky 40206

502-895-2405 • 800-223-1839

www.aph.org[email protected]