The "If < > Then" Block
-
Prerequisite
Description
The “If <> then” block is a C block in the control category.
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.
The condition is checked only once
The “If <> then” block checks its condition only once.
Nested If <> then Blocks
If you put one “If <> then” block inside the other, they become “Nested”.
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.
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”.