Snap Lesson 8: Loops
In this lesson we will learn about loops and how to repeat things


 Now what if we wanted to make the CoDrone do the same thing repeatly. So far with what we have learned we would have to put the same code in over and over, but there is an easier way.





  • This block will repeat the code for however many times is inputted
  • Once it has repeated the inputted amount of times it will exit and continue the code below it

To show how this works we will make a code that will blink the LEDs 5 times.

This will switch between blue and red 5 times, each time waiting 1 second to switch color.

We can use this in our CoDrone code too. Lets say we wanted to fly in a square 5 times. we can use a loop to repeat our square code 5 times. Or to save even more coding we can use it to go forward and make a 90 degree turn then repeat 20 times (4 side of a square times 5 squares = 20):


But what if we wanted it to repeat forever? There is the forever block to do that. This block will make it repeat the code until the stop button is pressed. So to make it move in a square forever:

Activity: Circle

Challenge Rules:

  1. Using only one turn and one forward inside of a repeat make the CoDrone fly in a cirlce
  2. Try to make it circle an object or a point on the ground
  3. An easy way to think of it is look at a octagon, it has a flat side, then an angle, and repeats this until it makes the octagon. If you make it with more smaller sides it will look like a circle.