lesson

Updated 6 days ago ยท 2 views
Imagine you want your best friend to do 20 jumping jacks. Would you rather shout "Jump!" twenty separate times, or just say "Do 20 jumping jacks" once?
In computer science, we use a shortcut called a loop, which tells someone or something to repeat actions without listing every single step.
How much easier does a loop make our instructions? Let's compare them side by side.
The Repeat Shortcut
A repeat command tells a partner two things: what action to do, and how many times to repeat it.
๐Interactive diagram
Now that we know the shortcut, how do we play this game with a real partner?
Programmer and Robot
In this unplugged game, one person is the programmer who writes the code, and one person is the robot who follows every command exactly.
You can group multiple movements inside one repeat block to create a fun dance routine.
๐Interactive diagram
What happens if you want your robot to cheer after the dance is completely finished?