a1tD00000087zpIIAQ

# Course: Programming with CoDrone Lite5-Loops with CoDrone Lite

• Beginner

### Lesson Description:

Loops will be part of almost every program that a student makes to fly their CoDrone. These lessons will cover what loops are and how they work, and then students will create and run their own programs using loops. In this lesson, students will include loops in their programs and create a program that climbs a staircase.

Objective:

• Explain what a loop is, how it works, and why it is used with choreography. Create and run a program in Snap that involves both simple and combined loops that has a drone flying in a staircase pattern.

## Teaching Tips:

• Have students talk in groups to figure out what a loop is and how it might be used in programming.
• Split students up into teams and have them choreograph their own dances. The choreography should be 30-60 seconds, school appropriate, and should have at least three repeated series of steps. Once their dance is choreographed, they will need to write out their dance steps and anything that is a loop should have a bracket around the step with loop written next to it.  Next, they will pass their written choreography to the team on their left and perform their dance moves according to the instructions. Performances will need to be done one at a time so the team that wrote the choreography can see if their instructions made sense.
• Which groups were successfully able to perform? What helped them out? Which groups were not successfully able to perform? What problems did they run into? What do they think a computer or robot would do in that situation and how would they fix it?

## Teaching Tips:

This section is talking about the different types of loops that can be programmed with Snap!. The types of loops and how to program them can be shown to the students using ClassView. In the main section that you and the students can see, an overview of the three types of loops is presented.

See below the answer to the question:

You have three programs that you need loops for. Which loop would you use for each program? Each type of loop is used only once. Discuss with your classmates:

1. For playing your favorite song three times

The For loop is needed.

1. For flying your CoDrone until the space key is hit

The Until loop is needed

1. For keeping a digital clock running

The Forever loop is needed.

### There are several types of loops that you can create with Snap!

1. Forever loop

Just like their name says, forever loops repeat the code within them forever. If you're suspicious about this, look at the bottom of the forever loop block. It's missing the connector at the bottom, so the code will never exit out of the loop and move on.

2. For loop

For loops repeat the code within them for an amount of time that you set. Once the code has been repeated for that amount of time, your program will exit out of the loop and move on to the rest of your code. The block in the program is called "Repeat".

3. Until loop

Until loops repeat until the condition you set in the diamond/hexagon-shaped space is true. Each time the program runs through the repeat until loop, it checks to see if the condition is true. If the condition is true, that doesn't mean the code automatically stops! The code stops when the condition is true AND when the code in the loop is finished. The bloc is called " Repeat Until".

### You have three programs that you need loops for. Which loop would you use for each program? Each type of loop is used only once. Discuss with your classmates:

1. For playing your favorite song three times
2. For flying your CoDrone until the space key is hit
3. For keeping a digital clock running

## Teaching Tips:

• Ask students to use pseudocode to explain to a partner how they got their drone to move in a square or staircase pattern in Snap using both their own words and the appropriate academic language.
• Have students complete the Stair Challenge in the Loops in Flight lesson. For an extra challenge, have obstacles set up in ascending to descending height that the students will need to avoid. The students who successfully complete the challenge with the least amount of blocks win!

### Challenge

Activity: Stair challenge

Make your CoDrone fly up a set of stairs (fly up, forward, up, forward, etc) and then fly back down!

Challenge rules:

1. Use variables for delays.
2. Use loops for any code that will be repeated more than once. Hint: you should have two loops in your program!
3. Your CoDrone has to fly up at least three stairs.
4. Your CoDrone needs to land!

## Teaching Tips:

Have students answer the following questions to asses their understanding of the lesson. If there is time left, you can make students share their answers and experiences.

What is a loop? Why would a programmer use loops in their code?

Explain one of your program using pseudocode.