1 Answers
📚 Quick Study Guide: Conditionals in Scratch
- 💡 What are Conditionals? Conditionals are programming constructs that allow a program to make decisions and execute different code blocks based on whether a specified condition is true or false. In Scratch, these are primarily found in the 'Control' block category.
- 🤔
If ThenBlock: This block executes the code inside it only if its boolean condition is true. If the condition is false, the code inside is skipped, and the program continues to the next block after theif thenblock. - 🔄
If Then ElseBlock: This block provides two paths. If the boolean condition is true, the code in the 'if' section runs. If the condition is false, the code in the 'else' section runs. One path will always be executed. - ⚖️ Boolean Operators (Sensing & Operators Blocks): Conditions are formed using 'Sensing' blocks (e.g.,
touching [mouse-pointer]?,key [space] pressed?) and 'Operators' blocks (e.g.,<,>,=,and,or,not). These blocks always return atrueorfalsevalue. - 🧩 Nesting Conditionals: You can place one conditional block inside another (nesting) to handle more complex scenarios where multiple conditions need to be checked in sequence or hierarchy. This is crucial for sophisticated algorithms.
- ✅ Common Applications: Conditionals are vital for game logic (e.g., collision detection, scoring, changing levels), interactive stories (e.g., character choices, different endings), and user input validation.
🧠 Practice Quiz: Algorithms with Conditionals
1. What is the primary purpose of an if then block in Scratch?
- To repeat a set of actions a specific number of times.
- To make a sprite move to a random position.
- To execute a block of code only when a specified condition is true.
- To broadcast a message to other sprites.
2. Which of the following Scratch blocks is an example of a boolean condition that returns either true or false?
move 10 stepssay Hello!touching color [red]?change x by 10
3. You want a sprite to say "Too cold!" if the temperature variable is less than 0, and "Just right!" otherwise. Which conditional block would be most appropriate?
- A
repeat untilblock - An
if thenblock - An
if then elseblock - A
wait untilblock
4. If you have an if then block with the condition (score > 100) and (level = 5), when will the code inside the if then block execute?
- Only if the score is greater than 100.
- Only if the level is 5.
- If either the score is greater than 100 OR the level is 5.
- If BOTH the score is greater than 100 AND the level is 5.
5. What happens if the condition in an if then block is false?
- The sprite stops all scripts.
- The code inside the
if thenblock is executed once. - The program will wait indefinitely.
- The code inside the
if thenblock is skipped, and the program continues after it.
6. You want a sprite to change its costume if it touches the edge OR if the 'game over' variable is true. Which operator block would connect these two conditions?
andnotor=
7. Consider the following nested conditional structure:if (A is true) then if (B is true) then // Code Block X else // Code Block Yelse // Code Block Z
If A is false, which code block will execute?
- Code Block X
- Code Block Y
- Code Block Z
- None of the above
Click to see Answers
1. C (To execute a block of code only when a specified condition is true.)
2. C (touching color [red]? is a boolean condition that evaluates to true or false.)
3. C (An if then else block is perfect for two mutually exclusive outcomes based on a condition.)
4. D (The and operator requires both conditions to be true for the overall condition to be true.)
5. D (The code inside the if then block is skipped, and the program continues after it.)
6. C (The or operator allows the action to happen if at least one of the conditions is true.)
7. C (If A is false, the program immediately jumps to the else part of the outer conditional, executing Code Block Z.)
Join the discussion
Please log in to post your answer.
Log InEarn 2 Points for answering. If your answer is selected as the best, you'll get +20 Points! 🚀