Here’s a fun fact about computers: they never get bored. It doesn’t matter how many times you tell them to do a certain task; they’ll keep doing it with 100 percent enthusiasm. If only we humans could muster the same energy when it comes to repetitive tasks.
This article is all about repetition. When you need to repeat the same activity or check the same thing over and over again in your code, you can use something called a loop. Loops exist in every coding language and help seasoned and beginner coders alike save valuable time. So let’s jump right into it.
Programming loops explained
So, what are loops? Just like the name implies, loops are things that repeat. They go round and round and round and round again. Loops don’t go on infinitely, though. Instead, they stop when they’re told, they reach a particular conclusion, or they repeat a pre-set number of times.
The benefits of loops are two-fold. One, they save you, the coder, time. You don’t have to write out the same instructions over and over. And two, they help keep your code organized. We know you and your students or kids are only now learning about loops in code. Still, as you blossom into unstoppable, innovative, and imaginative programmers, your code will become increasingly complex. The neater you can keep it, the better – loops are an invaluable organizational tool.
Learning about loops with kids – the fun way
Coding for beginners doesn’t have to be technical and dry – even when it comes down to the nitty-gritty. We help kids learn about programming loops in a way that’s fun, visual, and interactive. How? With our good friend, the robot.
Robots are computers – they don’t have common sense. Coders need to tell robots precisely what to do. If you want a robot to make you scrambled eggs, you can’t just say, ‘Hey, robot! Make me scrambled eggs.’ You have to give the robot clear step-by-step instructions in a language it understands (AKA code).
In the loops for kids video, we use the example of climbing a flight of stairs. Remember, our robot needs very specific instructions – right leg up, forward, down, left leg up, forward, down, and so on.
If you want the robot to climb ten, twenty, or one hundred stairs, you have two options. You can give the ‘right leg up, forward, down, left leg up, forward, down’ instruction ten, twenty, or one hundred times. Or you can use a counting loop to make your life a whole lot easier. You can pop the instructions in a loop and tell the robot how many times to repeat the pattern. So. Much. Easier.
Sequences and loops in coding
Sequences and loops are like best buddies (and if you need a quick re-cap on sequences, check out lesson three in our Camp Coding Camp series). So when you or your young learners write out a sequence, pay attention to the steps or instructions that repeat. Can you spot a pattern? Could you add a loop or two to make your code shorter and more organized?
That’s the beauty of learning coding basics – they give you the tools you need to transform your ideas into a reality!
Watch our loops song for kids
Ready to see the time-saving power of loops in action? Watch our programming song now and teach computer science for beginners to the kids in your life. Learning how to code has never been more fun!
Did you know that Scratch Garden has a 2nd Channel? With a growing library of more than 50 videos?
It's all true! We have created a whole other channel on Patreon! Patreon allows creators like Scratch Garden to offer a kind of membership for special fans like you. In exchange for your support, you can access monthly patron-only content like behind-the-scenes videos, Halloween and holiday videos, as well as many hilarious Blooper Videos!
For as little as $2/month you can watch all these videos AND help support Scratch Garden to keep making great fun educational content.