The if block

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

The if block

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. What does the if block do?
A It runs the blocks inside it only when its condition is true
B It runs the blocks inside it every time, no matter what
2. Where does the condition go in an if block?
A In the hexagon slot next to the word if
B Inside the blocks in the middle of the C shape
3. Which blocks run if the condition is false?
A None of the blocks inside the if block
B All of the blocks inside the if block
4. Which block belongs inside an if block so the sprite says 'Ouch!' only when it touches the edge?
A say Ouch! (placed above the if block)
B say Ouch! (inside the if touching edge? block)
5. Which one fits in the condition slot of an if block?
A move 10 steps
B score > 10

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1if <score > 10> then AThe sprite turns only when it is touching the edge. Otherwise the turn block is skipped.
2if <touching edge?> then turn 15 degrees BThe blocks inside this if block run only when the score is greater than 10.
3The condition goes in the hexagon slot of the if block Cif <answer = yes> then say Great!
4Blocks that should only run sometimes go inside the if block DThe say block is outside the if block, so it runs every time, even when the score is 10 or less. It should be placed inside the if block.
5if <say Hello> then EA say block was put in the condition slot. The slot needs a true or false question, like <answer = yes>. The say block should go inside the if block.
6if <score > 10> then say You win! (say is outside the if) Fif <key space pressed?> then

Definitions

if <condition> then

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
__ <score > 10> then say(You win!) end
2.
if <lives = 0> ____ say(Game over) end
3.
if <score _ 10> then say(Well done!) end
4.
if <score > 10> then ___(You win!) end
5.
if <touching edge?> then turn 15 degrees ___

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A if <score + 10> then
B say [You win!]
C end
Question 2
A when green flag clicked
B if then <touching [Ball]?>
C say [Got it!] for 2 seconds
D end
Question 3
A when green flag clicked
B set [score] to 12
C if <score > 10> then
D say <Well done!>
E end
Question 4
A when green flag clicked
B if <score > 9> then
C say [High score!]
D then
Question 5
A when green flag clicked
B ask [Ready?] and wait
C if <answer> then
D say [Let's go!]
E end

Answer Key

The if block
Section A: Quick Questions
Q1
A — It runs the blocks inside it only when its condition is true
Q2
A — In the hexagon slot next to the word if
Q3
A — None of the blocks inside the if block
Q4
B — say Ouch! (inside the if touching edge? block)
Q5
B — score > 10
Section B: Match the Pairs
Q1
if <score > 10> then → The blocks inside this if block run only when the score is greater than 10.
Q2
if <touching edge?> then turn 15 degrees → The sprite turns only when it is touching the edge. Otherwise the turn block is skipped.
Q3
The condition goes in the hexagon slot of the if block → if <key space pressed?> then
Q4
Blocks that should only run sometimes go inside the if block → if <answer = yes> then say Great!
Q5
if <say Hello> then → A say block was put in the condition slot. The slot needs a true or false question, like <answer = yes>. The say block should go inside the if block.
Q6
if <score > 10> then say You win! (say is outside the if) → The say block is outside the if block, so it runs every time, even when the score is 10 or less. It should be placed inside the if block.
Section C: Definitions
Q1
if <condition> then — A block that runs the blocks inside it only when its condition is true. If the condition is false, it skips them. The condition goes in the hexagon slot.
Section D: Fill in the Blanks
Q1
if <score > 10> then say(You win!) end
Q2
if <lives = 0> then say(Game over) end
Q3
if <score > 10> then say(Well done!) end
Q4
if <score > 10> then say(You win!) end
Q5
if <touching edge?> then turn 15 degrees end
Section E: Spot the Error
Q1
A — The slot needs a true or false condition. Score + 10 makes a number, not true or false. It should be if <score > 10> then.
Q2
B — The condition goes in the hexagon slot straight after if, and then comes after it. It should be if <touching [Ball]?> then.
Q3
D — The say block takes text in a rounded slot. The hexagon shape is only for conditions. It should be say [Well done!].
Q4
D — An if block must be closed with end after the blocks inside it. The word then belongs on the first line. Line 4 should be end.
Q5
C — The answer on its own is text, not true or false. The condition must compare it, like <answer = [yes]>.