The "If < > Then" Block
-
Prerequisite
Description
The “If <> then” block is a C block in the control category.
https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/ca0a4385-50ad-4e93-8690-6ac76394bce5.PNG" width="550" style="">
How does this block work?
This block runs the blocks inside its mouth if the condition is true. If the condition is false, it ignores the blocks inside it and continues to the blocks below it.
https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/3431c75b-7251-4ae7-b713-0e0d4ca5ec2a.gif" width="800" style="border-radius: 5px; border: 1px solid #29622d;">
The condition is checked only once
The “If <> then” block checks its condition only once.
https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/b12fe4b6-d1c6-4b31-b376-8248da659230.gif" width="800" style="border-radius: 5px; border: 1px solid #29622d;">
Nested If <> then Blocks
If you put one “If <> then” block inside the other, they become “Nested”.
https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/058daa25-6d57-4bdd-a3c2-6a125d65a691.PNG" width="150" style="">
You can use Nested “if <> then” blocks when you want to check another condition when the first condition turns out to be true.
For example, as shown below, the first “If” block checks if the sprite is touching the “Start” sprite or not. if it is “true” then the second “If” block checks if the “x-position” is greater than 10. The sprite will say “Game started” when both conditions are true.
https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/467095fd-794c-4309-9de9-c2fee841a11f.gif" width="800" style="border-radius: 5px; border: 1px solid #29622d;">
Multiple If <> then Blocks
You can stack multiple “If <> then” blocks together to check multiple conditions at the same time.
For Example, as shown below, if the score is less than or equal to “5”, the sprite will say “I’m sad”; if the score is greater than or equal to “10”, the sprite will say “I’m happy”.
https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/a47baca3-bb22-48b8-9fb7-0ea507098141.gif" width="800" style="border-radius: 5px; border: 1px solid #29622d;">
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login