📖 Quick Study Guide: Understanding Scratch 'If-Then' Blocks
- 🎯 Purpose: The 'If-Then' block is a control block used for conditional execution. It allows a specific set of actions to run only if a given condition is true.
- 🏗️ Structure: It looks like a 'C' shape with a hexagonal slot at the top. Code blocks placed inside the 'C' will execute.
- ✅ Condition Type: The hexagonal slot is designed to hold a Boolean (true/false) block. This condition must evaluate to either true or false.
- 🚫 Execution Logic: If the condition in the hexagonal slot is true, the blocks inside the 'If-Then' block will run. If the condition is false, the blocks inside are skipped entirely, and the script continues with the next block after the 'If-Then' structure.
- ↔️ Common Conditions: You'll often use sensing blocks (e.g., `touching [mouse-pointer]?`, `key [space] pressed?`), operators (e.g., `[variable] > 10`, `[answer] = "yes"`), or custom boolean blocks.
- ➕ Combining Conditions: For more complex logic, you can combine multiple conditions using Boolean operators like `and`, `or`, and `not` (found in the Operators category).
- 🆚 'If-Then' vs. 'If-Then-Else': The key difference is that 'If-Then' only specifies actions for when the condition is true. 'If-Then-Else' provides an alternative set of actions to execute when the condition is false.
- 🎮 Applications: Essential for game development (e.g., checking for collisions, scoring points, changing levels) and creating interactive stories.
🧠 Practice Quiz: Test Your 'If-Then' Skills!
- What is the primary function of an 'If-Then' block in Scratch?
A. To repeat a set of actions a specific number of times.
B. To execute a set of actions only when a certain condition is met.
C. To define a new custom block or function.
D. To broadcast a message to other sprites. - Which type of block is designed to fit into the hexagonal slot of an 'If-Then' block?
A. A motion block (e.g., `move 10 steps`).
B. A Boolean (true/false) block (e.g., `touching color []?`).
C. A number block (e.g., `100`).
D. A string block (e.g., `"Hello"`). - If the condition within an 'If-Then' block evaluates to 'false', what happens to the code blocks placed inside the 'C' shape?
A. They run once, then the script stops.
B. They run continuously until the condition becomes true.
C. They are skipped entirely, and the script continues with the next block after the 'If-Then'.
D. The entire Scratch project pauses. - Which of the following scenarios is best suited for an 'If-Then' block, rather than an 'If-Then-Else' block?
A. Changing a sprite's costume if a key is pressed, otherwise saying "Waiting".
B. Moving a sprite forward if it's touching a wall, otherwise turning around.
C. Increasing a score if a target is hit, with no action if it's missed.
D. Displaying "Game Over" if health is zero, otherwise continuing the game. - Consider the following Scratch script: `when green flag clicked`, `forever`, `if then`, `change x by 10`. What will happen when the green flag is clicked?
A. The sprite will continuously move right, regardless of key presses.
B. The sprite will move right only when the space key is held down.
C. The sprite will move right once when the space key is pressed, then stop.
D. The script will wait indefinitely for the space key to be pressed. - Which of these is a valid condition that could be placed inside an 'If-Then' block?
A. `say "Hello!"`
B. `[score] > 100` (an operator block comparing a variable to a number)
C. `go to x: (0) y: (0)`
D. `wait (1) seconds` - Why are 'If-Then' blocks considered fundamental for creating interactive games in Scratch?
A. They allow sprites to communicate with each other using messages.
B. They control the speed and direction of sprite movement.
C. They enable responsive behaviors based on player input or game state.
D. They are primarily used for changing the backdrop.
Click to see Answers
1. B
2. B
3. C
4. C
5. B
6. B
7. C