# Lesson 8: Loops Unplugged: Happy Loops

## Overview

Loops are a very helpful and powerful tool in programming. To understand how helpful loops can be, students will need to be driven to want an easier way to solve mundane problems.

## Purpose

This lesson serves as an introduction to loops. Loops allow for students to simplify their code by grouping commands that need to be repeated. Students will develop critical thinking skills by noticing repetition in movements of their classmates and determining how many times to repeat the commands inside of the loops. By seeing "Happy Maps" again, students will be able to relate old concepts such as sequencing to the new concept, loops.

## Objectives

### Students will be able to:

• Identify repetitive code and convert a series of multiple actions into a single loop.
• Decode loops into a series of multiple actions.

## Preparation

Heads Up! Please make a copy of any documents you plan to share with students.

## Vocabulary

• Loop - The action of doing something over and over again.
• Repeat - Do something again

# Teaching Guide

## Warm Up (10 - 15 min)

### Such a Long Walk

Goal: This portion of the lesson should help students see that there is an easier way to handle repetitive code than to brute force a solution with dozens of the same symbols.

Recall the "Happy Maps Programming" activity with your students. Recall the limited pieces that they had to work with (up, down, left, right). Then, pull up one of the new -- and much longer -- Happy Maps XL.

Can your students help you program these maps? It takes a while, doesn’t it? What can you do if you run out of arrow pieces?

### Discuss

Give students the opportunity to brainstorm shorter ways to relay the code that they’re creating. (This bit can be skipped over if your students start saying things like: “Move forward 6 times.” Since that will open the discussion about how to show “six times” with symbols.)

Once students have put together the idea of “repeating” code, give them the vocabulary around it. Make sure to share with them that often the terms “repeat something” and “loop something” will be used interchangeably in Code Studio.

### Vocabulary

• Loop: the act of doing something over and over and over.
• Repeat: doing something again.

Notice: Loops repeat a step over and over again.

## Main Activity (15 - 20 min)

### Happy Loops

Now that students are familiar with the ability to repeat lots of code using a single loop, select an XL map and let them help you code the situation. Do this as many times together as a class as you need, then set students off in groups to solve some problems on their own. You will also need to add the Happy Maps Game Pieces Bonus Pack to adapt this activity for loops.

Make sure to walk around and have students run through their code with you watching. Are there any bugs? Use the debugging questions to help them find a solution.

• What does it do?
• What is it supposed to do?
• What does that tell you?
• Does it work at the first step?
• Does it work at the second step?
• Where does it stop working

## Wrap Up (8 min)

### Journaling

Having students write about what they learned, why it’s useful, and how they feel about it can help solidify any knowledge they obtained today and build a review sheet for them to look to in the future.

#### Journal Prompts:

• Ask students to draw a feeling face in the corner of their journal page to remind them how they felt about this lesson.
• Have the students write or draw something in their journal that will remind them later what loops are. Prompts include:
• What does "repeat" mean to you?
• Draw a picture of you repeating something.

## Extension Activities

• Create a life-size grid on the rug with tape and have student bring stuffies to school. Now students can program friends to move their actual stuffies as directed in the programs.
• Have students create their own maps for other students to solve using loops.
• Draw a program on the board that uses several sets of repeated commands and have students take turns coming to the front to swap symbols for repeat loops.

## Standards Alignment

#### CSTA K-12 Computer Science Standards

AP - Algorithms & Programming
• 1A-AP-09 - Model the way programs store and manipulate data by using numbers or other symbols to represent information.
• 1A-AP-10 - Develop programs with sequences and simple loops, to express ideas or address a problem.
• 1A-AP-14 - Debug (identify and fix) errors in an algorithm or program that includes sequences and simple loops.