GiggleBot - The Micro:Bit Robot
GiggleBot - The Micro:Bit Robot
Cart 0

micro:bit Programming - Make a For Loop

bbc microbit robot for loop for loop gigglebot for loop microbit microbit robot robot

In this tutorial we'll go over how to make a "for loop" for our Micro:Bit robot the GiggleBot.  We will make the robot move forward and make a rainbow smile four times (or as many times as you like!).

What's a For Loop?

for loop for micro bit robot

A for loop is a loop that will repeat a section of code a specific number of times.  You can think of it as a way to tell a computer or robot to do something over and over and over again  . . . so many times.

So where do you find the "repeat" block?  You find it under loops!

for loop location micro bit

For Loop Robot Example for the Micro:Bit Robot

In this example, we'll show you how to write a For Loop.

Say we want to drive forward for 1 second and stop and make the GiggleBot smile.  But we want to do that 4 times.  

Here's the hard way to make that happen:

for loop four times

It takes 8 blocks to make the robot move forward and stop ten times.  

How Do You Make a For Loop in MakeCode?

We make make the robot move forward 1 second and stop, but do this a lot more easily.  If we use "For Loops" or "repeat" blocks.  Again, a for loop on the Micro:Bit shows us how to loop and repeat a section of code or commands a number of times.  In this case, we want the robot to "move forward for 1 second and stop", four times. 

 

How Do You Make a For Loop in Python?

Bonus, we can make a for loop in Python for the Micro:Bit as well!


Newer Post