GoalSay what selection is and name the condition and the conclusion in an if … then statement.
New words
selection · a decision in a program: it checks a condition and chooses what to docondition · a question that is either true or falseconclusion · the steps that are carried out only when the condition is trueif … then · a statement that runs its conclusion only when its condition is true
Explanation
Selection means that a program makes a decision. An if … then statement has two parts. The condition comes after ‘if’. It is a question that is either true or false. The conclusion comes after ‘then’. It is carried out only when the condition is true. If the condition is false, the program skips the conclusion and goes on. We make these decisions every day: ‘If it is dark, then I switch on the lamp.’ In Scratch the if block holds the condition in its pointed slot, and the blocks inside it are the conclusion.
Worked examples
Statement
Condition
Conclusion
If it is dark, then I switch on the lamp.
it is dark
I switch on the lamp
If the shop has bread, then we buy two loaves.
the shop has bread
we buy two loaves
If the match is cancelled, then the team goes home.
the match is cancelled
the team goes home
Each of these everyday statements has a condition and a conclusion.
The condition decides the path. When the answer is yes (true), the conclusion is carried out. When it is no (false), the program skips it.
Here is a small program. The Mouse goes to x: -120, y: -40 and moves 100 steps, so it ends at x: -20. The Cheese sits at x: -20, y: -40. The Mouse is touching the Cheese, so the condition is true. The if block holds two blocks, and both of them are the conclusion: the Mouse says ‘Yum!’ and the pop sound plays.
Class activity
Card checker (3 or more players). One player is the checker. The checker holds a rule card such as ‘If the card shows an even number, then say Yes!’. The other players hold number cards and show them one at a time. The checker says the conclusion only when the condition is true, and stays silent when it is false. Swap roles and invent new rules, for example about colours or animals. For each rule, point to the condition and the conclusion.
Practice
1
Find the condition and the conclusion. (a) If I finish my reading, then I can draw. (b) If the pool is closed, then we go to the park.
(a) Condition: I finish my reading. Conclusion: I can draw. (b) Condition: the pool is closed. Conclusion: we go to the park.
2
The flag is clicked and the left arrow key is not being pressed. What does the sprite do?
Nothing. The condition is false, so the conclusion is skipped. There is no forever block, so the condition is checked only once.
3
Write your own if … then statement about a game or a sport. Underline the condition and circle the conclusion.
Answers vary, for example: If the ball goes into the net, then the team scores a goal. Condition: the ball goes into the net. Conclusion: the team scores a goal.
4
Sort these blocks into conditions and conclusions.
Conditions: touching Tree and key space pressed. Conclusions: say Ouch! for 2 seconds and hide.