💡 Quick Study Guide: If-Then-Else in Scratch
- 🤔 Conditional Logic: 'If-Then-Else' blocks allow your Scratch projects to make decisions based on whether a condition is true or false.
- ✅ If-Then: This block executes a set of commands only if a specified condition is true. If the condition is false, the commands inside the 'If' block are skipped.
- ↔️ If-Then-Else: This block offers two paths. If the condition is true, the commands in the 'If' section run. If the condition is false, the commands in the 'Else' section run instead.
- ⚙️ Boolean Conditions: The hexagonal input slot in 'If-Then-Else' blocks expects a Boolean (True/False) condition, often created using operators (e.g., `=`, `>`, `<`, `and`, `or`, `not`) or sensing blocks (e.g., `touching color?`, `key pressed?`).
- 🔁 Placement: Conditional blocks are often placed inside loops (like `forever` loops) to continuously check conditions and react to changes in the project.
- 🚫 Avoiding Errors: Ensure your conditions are clear and cover all possible scenarios to prevent unexpected behavior in your scripts.
🧠 Practice Quiz: If-Then-Else in Scratch
1. What is the primary purpose of an 'If-Then' block in Scratch?
- A. To repeat a set of actions a specific number of times.
- B. To make a sprite move in a random direction.
- C. To execute a block of code only if a condition is met.
- D. To broadcast a message to other sprites.
2. In an 'If-Then-Else' block, when does the code inside the 'Else' section execute?
- A. When the condition is true.
- B. When the condition is false.
- C. Always, regardless of the condition.
- D. Only when the green flag is clicked.
3. Which type of value does the hexagonal input slot of an 'If-Then-Else' block require?
- A. A number (integer or decimal).
- B. A string of text.
- C. A Boolean (true or false) value.
- D. A sprite name.
4. Imagine a Scratch script: "If (key [space] pressed?) Then (say 'Jump!' for 2 seconds)". If the space key is NOT pressed, what will happen?
- A. The sprite will say "Jump!".
- B. The sprite will wait 2 seconds.
- C. Nothing inside the 'If' block will execute.
- D. The project will stop immediately.
5. Which of these Scratch blocks is commonly used to create the condition for an 'If-Then-Else' block?
- A.
move (10) steps - B.
say (Hello!) - C.
(mouse down?) - D.
change [score] by (1)
6. What is the benefit of using an 'If-Then-Else' block instead of just an 'If-Then' block when you need different actions for true and false conditions?
- A. It makes the script run faster.
- B. It allows for more complex animations.
- C. It provides a clear, single structure to handle both outcomes of a condition.
- D. It automatically creates a loop.
7. In a game, you want your sprite to say "Game Over!" if its health drops to 0, otherwise it should say "Keep Going!". Which conditional block is most appropriate?
- A. An 'If-Then' block.
- B. A 'Repeat' block.
- C. An 'If-Then-Else' block.
- D. A 'Forever' block.
Click to see Answers
1. C: 'If-Then' blocks are for conditional execution.
2. B: The 'Else' part runs when the condition is false.
3. C: Boolean values (true/false) are required for conditions.
4. C: If the condition is false, the code inside 'If' is skipped.
5. C: (mouse down?) is a Boolean sensing block.
6. C: 'If-Then-Else' provides a dedicated path for both outcomes.
7. C: 'If-Then-Else' is perfect for two distinct actions based on a condition.