Lesson 9 of 10

🔀 Making Decisions

🎯 Grades 3–5 ⏱ ~25 minutes 💚 Intermediate

What You'll Learn

  • Understand what a conditional (if statement) is
  • Use the If Near Edge block to make the turtle react to the world
  • See how programs can make choices on their own

What Is a Conditional?

So far your programs always run the same blocks in the same order, no matter what. But real programs can make decisions. A conditional is a block that checks a question and only runs if the answer is yes.

You already use conditionals every day:

  • 👣 If it is raining, bring an umbrella.
  • 🌿 If the light is red, stop. If the light is green, go.
  • 🐱 If the cat meows, feed it.

Computers do the same thing. They check a condition, then decide what to do.

💡
Key Idea

A conditional says: "IF this is true, THEN do this." The code inside only runs when the condition is true.

The If Near Edge Block 🔀

We have one conditional block: If Near Edge → Turn Around. It checks: "Is the turtle within 30 pixels of the edge of the canvas?"

  • If yes — the turtle turns 180° (turns around) and the block flashes to show it fired
  • If no — nothing happens; the program continues
🔎
How It Works

The block secretly checks the turtle’s position every time it runs. If the turtle is too close to any wall, it automatically reverses direction. You do not have to count steps or plan it — the block handles it!

Conditionals + Loops = Smart Programs

A conditional by itself only checks once. But when you put it inside a loop, the turtle checks the condition on every step — and reacts automatically. That is how you make a turtle that bounces around the canvas forever without falling off the edge!

Try this recipe:

  1. Add If Near Edge to your sequence
  2. Add Move Forward after it
  3. Set Repeat to 20
  4. Click Run and watch the turtle navigate on its own!
🔀 Bouncing Turtle

Build a program where the turtle moves across the canvas and automatically turns around whenever it gets near a wall. Challenge: can you make it draw a zig-zag path?

  1. Add If Near Edge → Turn Around
  2. Add Move Forward 60
  3. Set Repeat to 15
  4. Run — watch the turtle bounce!
  5. Bonus: Add a Turn Right between the two blocks and increase Repeat to 25. What happens?
Quick Check

What does a conditional block do?

ARepeats a set of blocks a fixed number of times
BChecks a condition and only acts if it is true
CChanges the turtle’s color

What happens when “If Near Edge” fires?

AThe turtle stops and the program ends
BThe turtle turns 180° (turns around)
CThe turtle teleports to the center

Why is combining a conditional with a loop useful?

AIt makes the program run faster
BIt makes the turtle draw a square
CThe condition is checked every step so the turtle reacts automatically