Studyfin Studyfin ✨ Sign up free

Loops

Grade 7 · Coding · Free lesson

Hi there! I am Studyfin, your coding pal. Today we are going to learn how loops help us solve problems without typing the same code over and over!

Imagine you want to paint a fence. Instead of writing 'paint block 1, paint block 2, paint block 3,' you can just use a loop! A loop is a programming tool that repeats a set of instructions until a goal is met.

In coding, we use a design process to solve real problems. First, we find the repetitive task. Then, we use a block-based loop to repeat that action automatically. This saves time and keeps our program clean.

Repeat Action

We can also add conditionals inside our loops. A conditional is an 'if-then' statement. For example, a robot loops its walking code, but IF it sees an obstacle, THEN it stops!

Loop: Walk forward until wall
✏️ Worked example

Let's design a program to water a row of five dry plants. We want to analyze the problem, create a sequence, and use a loop to solve it efficiently.

  1. Analyze: We have 5 dry plants in a row. The repetitive task is moving to a plant and watering it.
  2. Plan the sequence: 1. Move to next plant. 2. Pour water. 3. Check if we watered 5 times.
  3. Create the loop: Instead of writing these steps 5 times, we wrap them in a loop block that repeats exactly 5 times.
  4. Add a conditional: Inside the loop, we can add: IF a plant is already wet, THEN skip watering it.
  5. Test and Evaluate: Run the program! The robot successfully waters all dry plants and stops after the fifth one.
Want the full interactive lesson — quiz, animations, and Finn cheering them on?

More Coding lessons