Studyfin Studyfin ✨ Sign up free

Loops

Grade 4 · Coding · Free lesson

Hello! I am Studyfin, your coding buddy. Today, we will learn how to make our code shorter and smarter using loops!

Sometimes we want a computer to do the same action over and over. Writing the same instruction many times takes too long. A loop is a special coding tool that repeats actions for us.

ai generated

Imagine you want a character to take four steps forward. Instead of writing 'step forward' four times, you can use a loop block. This loop tells the computer to repeat the step action exactly four times.

REPEAT 4 TIMES Step Forward Loop repeats the action!

We can solve everyday problems with loops. If we want to water five plants in a row, we can use a loop. The loop tells us to water a plant, move to the next one, and repeat until all five are happy.

Looping: Water each plant!
✏️ Worked example

Let's design a program to help a robot clean up a room. There are 3 toy blocks scattered on the floor. We want the robot to pick up each block and put it in a toy box.

  1. Identify the goal: We want to move 3 toy blocks into the toy box.
  2. Find the repeated action: The robot needs to pick up a block, carry it to the box, and drop it inside.
  3. Count the repeats: Since there are 3 blocks, we need to do these steps exactly 3 times.
  4. Write the program sequence: Start with a 'REPEAT 3 TIMES' loop block.
  5. Put the actions inside the loop: Place the 'Pick up block', 'Move to box', and 'Drop in box' commands inside.
  6. Run the program: The robot will repeat the loop 3 times and clean all the blocks perfectly!
math
Want the full interactive lesson — quiz, animations, and Finn cheering them on?

More Coding lessons