Coding Activity: "Flex Your Loops Skills" Mission No. 4

Let's talk about loops. Loops are a command programmers use to repeat a part of their code until a task is complete. In this beginner loops activity, you'll create a fun exercise routine using loops. Get the activity worksheet here and watch the short video below!

Loops are important, because they help your code stay bug-free, keep your code short, and save you programming time.

Programmers use loops to keep their code DRY

Loops are useful in every day life, too! Any time you repeat the same task multiple times, you are looping an action!

We use loops to repeat actions in our every day life

Loops are especially helpful for a computer. Remember, a computer can't do anything unless it is given instructions by a human. Loops are one of the tools that a programmer can use to more easily give instructions to a computer.

Here's your mission: Create a fun fitness program for the fuzz family using loops in your instructions.

So you might be wondering - what do loops have to do with a workout routine?

Think about everything that you need to do to use a jump rope. You swing the rope up, the rope wings down, and you jump! swing rope up, swing rope down, jump! Repeat this same task over and over and over again. That's jumping rope!

We loop three actions when we jump rope

As a human, you wouldn't have to think about every single step separately - you would just do it as one fluid action! What if you wanted to explain how to jump rope to your fuzz friend who has never even heard of jump rope before?

A fuzz would not know how to jump rope

You would not say "jump rope ten times!" You would have to break down the instructions for every single step.

"(swing up, swing down, jump)(swing up, swing down, jump)(swing up, swing down, jump)(swing up, swing down, jump)(swing up, swing down, jump)(swing up, swing down, jump)(swing up, swing down, jump)(swing up, swing down, jump)(swing up, swing down, jump)(swing up, swing down, jump)"

Instead, you can use a loop in your code to keep things simple.

(swing up, swing down, jump) x 10

The result is the same - your fuzz will jump rope ten times. but the loop helps makes your code shorter and saves you the time it would take to write out all those repeating commands.

You can use a loop to say "jump rope 10 times"

Today, your mission mission is to create a fun workout program!  Include at least 3 exercises in your routine and decide how many times  each of the moves should be looped.

Let's take a look at an example from our fuzzFamily

They've shared with you their "Fuzzy Flex" program and we're all going to try it out together. Just do your best, it's ok if you need to practice the moves a few times!

We use a loop for each exercise. The loops tells us how many time to repeat.
  • First move - Jumping Jacks! One jumping jack looks like this. Our program says to loop this action 10 times. let's try it! Awesome job! (10x)
  • The next move is Push ups. One pushup looks like this. Let's loop this action 5 times. Nice work! (5x)
  • Final move - Side stretch. We will loop this action ten times. Here we go! (10x)

Nice job!  You completed the fuzzy flex program.

Imagine how long and difficult the The Fuzzy Flex program would have been to write and to follow, if we couldn't use loops!   For example, the instructions for 10 jumping jacks would looks like this!

Without a loop we would need to repeat the same lines many times

Now it's your turn! Create a fun fuzzy flex program of your own with at least 3 different exercise moves.

Your coding mission. use three loops to create a workout routine

Use a loop to show how many times each exercise should be repeated. Write out your program and share it with a friend or family member to test it out!

loops unplugged coding activity

Make changes to your loops as needed! If the moves are too easy, try increasing the number of times it should be repeated. Too hard? Take the number of loops down!

write your own loopy flex program

It's up to you. Good luck!

Ready for more ? Check out all the Coding Missions here.