Studyfin Studyfin ✨ Sign up free

Algorithms

Grade 6 · Coding · Free lesson

Welcome! Today we will learn how repeating steps in an algorithm makes coding easier.

An algorithm is a list of step-by-step instructions. We use algorithms in code to solve problems and draw shapes.

machine learning

Iteration means repeating a set of steps using a loop. When we analyze code, we see that iteration saves time and reduces errors.

REPEAT 8 TIMESLOOP

Imagine drawing an octagon. Without iteration, you need eight long lines of code. With a loop, you write just two lines and repeat them.

An Octagon
✏️ Worked example

Analyze the benefits of using iteration to draw an octagon instead of writing individual steps.

  1. 1. Identify the shape: An octagon has 8 equal sides.
  2. 2. Look at the code without iteration: You must write 8 move commands and 8 turn commands (16 total lines).
  3. 3. Look at the code with iteration: You write 1 loop command containing 1 move and 1 turn (3 total lines).
  4. 4. Compare the two methods: The loop uses much less code.
  5. 5. Conclude: Iteration makes the algorithm shorter, cleaner, and much easier to fix if you make a mistake.
algorithm
Want the full interactive lesson — quiz, animations, and Finn cheering them on?

More Coding lessons