Skip to main content

Lesson 2.2: Make a Choice with If

An if block uses a condition to decide whether a group of commands should run. A condition is an expression with a Boolean result.

When the condition is true, the commands inside the if branch run. When it is false, those commands are skipped. Execution then continues after the whole if block.

For example, if score >= 10 can print level complete. That message appears only when the current score meets the rule.

Indentation and block shape show which commands belong inside a branch. A command connected below the entire if block runs afterward, no matter which result the condition had.

Guided practice

Set temperature to 30. Add an if block that prints warm when temperature > 25. Add a second print block after the if that prints checked.

Run with values 30 and 20. For each run, predict both the condition result and output. Use Step to confirm that checked appears in both runs while warm appears in only one.

Loading the block workspace...

Ready to move on?

Only mark complete if you genuinely understand the material. Your progress will be saved in this browser.

Stuck on this lesson?

Ask about anything on this page. It can see which lesson you have open and which part you are reading.