🔀 Making Decisions
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.
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
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:
- Add If Near Edge to your sequence
- Add Move Forward after it
- Set Repeat to 20
- Click Run and watch the turtle navigate on its own!
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?
- Add If Near Edge → Turn Around
- Add Move Forward 60
- Set Repeat to 15
- Run — watch the turtle bounce!
- Bonus: Add a Turn Right between the two blocks and increase Repeat to 25. What happens?
What does a conditional block do?
What happens when “If Near Edge” fires?
Why is combining a conditional with a loop useful?