Making Decisions in Code
Programs become truly powerful when they can make decisions. The If () Then block allows your program to execute a set of blocks only when a certain condition is true — just like saying 'If it is raining, then take an umbrella.'
The If () Then block checks a condition. If the condition is true, the blocks inside it run. If the condition is false, those blocks are skipped entirely.

Structure of the If () Then Block
The If () Then block has two parts: the condition slot (where you place a relational or Boolean operator block) and the body (where you place the blocks to run if the condition is true).
Parts of the If () Then Block
Example: Checking a Score
Let's look at a simple example. We will check if the player's score is greater than 10, and if so, have Tobi say 'You are doing great!'
- Create a variable called Score and set it to a value.
- Add an If () Then block from the Control palette.
- Place the condition (Score > 10) inside the condition slot.
- Inside the body, add a Say () for () seconds block with the message 'You are doing great!'
- Click the green flag — Tobi will only speak if the Score is greater than 10.

The If () Then block only runs its body when the condition is true. If the condition is false, the program simply moves on to the next block without doing anything.

.webp&w=3840&q=75)
.webp&w=3840&q=75)
.webp&w=3840&q=75)
.webp&w=3840&q=75)
.webp&w=3840&q=75)