The if-else block

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

The if-else block

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. What does an if-else block do when its condition is true?
A It runs the blocks in the first part (the 'if' part) and skips the else part
B It runs both the if part and the else part
2. What does an if-else block do when its condition is false?
A It does nothing at all
B It runs the blocks in the else part
3. Which sentence describes an if-else block best?
A Two paths, but only one runs
B Two paths, and both always run
4. A sprite checks: if <score > 10> then say 'You win!' else say 'Keep trying!'. The score is 4. What does the sprite say?
A Keep trying!
B You win!
5. A sprite checks: if <answer = 7> then say 'Correct!' else say 'Try again'. The answer is 7. What happens?
A The sprite says 'Correct!' and then 'Try again'
B The sprite says 'Correct!' only

Match the Pairs

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

Left columnRight column
1if <touching color [red]?> then ... else ... AIf the score is more than 9, the sprite says You win!. If not, the sprite says Keep going! Only one message appears.
2if <(score) > 9> then say [You win!] else say [Keep going!] Bif <key [space] pressed?> then move (10) steps else turn (15) degrees
3The blocks in the else part run only when the condition is false. CBoth paths do the same thing, so the condition makes no difference. The else part should have different blocks, such as say Try again!.
4An if-else block gives two paths, but only one of them runs each time. DThere is no else part. A message for the false case should be in the else part, not joined on with 'and', or both messages would be said.
5if <(lives) = 0> then say [Game over] and say [Keep playing] Eif <(answer) = [yes]> then say [Great!] else say [Maybe next time]
6if <(score) > 5> then say [Well done!] else say [Well done!] FChecks the condition. If it is true, the first set of blocks runs. If it is false, the else set of blocks runs.

Definitions

if <> then ... else ...

Fill in the Blanks

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

1.
__ <score > 10> then say [You win!] else say [Try again]
2.
if <score > 10> then say [You win!] ____ say [Try again]
3.
if <score _ 10> then say [You win!] else say [Try again]
4.
if <age < 8> then say [Hello, little one!] else ___ [Hello, big kid!]
5.
if <score > 10> ____ say [You win!] else say [Try again]

Spot the Error

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

Question 1
A ask [Is it raining?] and wait
B if <answer = yes>
C say [Take an umbrella]
D else
E say [Wear a cap]
F end
Question 2
A if <touching edge?> then
B turn 15 degrees
C otherwise
D move 10 steps
E end
Question 3
A if <score > 10> then
B say [You win!]
C else <score < 10>
D say [Try again]
E end
Question 4
A when green flag clicked
B if <lives = 0> then
C say [Keep going]
D else
E say [Keep going]
F end
Question 5
A if <coins + 10> then
B say [You are rich!]
C else
D say [Keep saving]
E end

Answer Key

The if-else block
Section A: Quick Questions
Q1
A — It runs the blocks in the first part (the 'if' part) and skips the else part
Q2
B — It runs the blocks in the else part
Q3
A — Two paths, but only one runs
Q4
A — Keep trying!
Q5
B — The sprite says 'Correct!' only
Section B: Match the Pairs
Q1
if <touching color [red]?> then ... else ... → Checks the condition. If it is true, the first set of blocks runs. If it is false, the else set of blocks runs.
Q2
if <(score) > 9> then say [You win!] else say [Keep going!] → If the score is more than 9, the sprite says You win!. If not, the sprite says Keep going! Only one message appears.
Q3
The blocks in the else part run only when the condition is false. → if <(answer) = [yes]> then say [Great!] else say [Maybe next time]
Q4
An if-else block gives two paths, but only one of them runs each time. → if <key [space] pressed?> then move (10) steps else turn (15) degrees
Q5
if <(lives) = 0> then say [Game over] and say [Keep playing] → There is no else part. A message for the false case should be in the else part, not joined on with 'and', or both messages would be said.
Q6
if <(score) > 5> then say [Well done!] else say [Well done!] → Both paths do the same thing, so the condition makes no difference. The else part should have different blocks, such as say Try again!.
Section C: Definitions
Q1
if <> then ... else ... — A block that runs the blocks in the first part if the condition is true, and the blocks in the else part if it is false. Two paths, but only one runs.
Section D: Fill in the Blanks
Q1
if <score > 10> then say [You win!] else say [Try again]
Q2
if <score > 10> then say [You win!] else say [Try again]
Q3
if <score > 10> then say [You win!] else say [Try again]
Q4
if <age < 8> then say [Hello, little one!] else say [Hello, big kid!]
Q5
if <score > 10> then say [You win!] else say [Try again]
Section E: Spot the Error
Q1
B — The if-else block needs the word then after the condition. Line 2 should be: if <answer = yes> then.
Q2
C — The second path of the block is called else, not otherwise. Line 3 should be: else.
Q3
C — The else part has no condition of its own. It runs whenever the if condition is false. Line 3 should just be: else.
Q4
C — The first path runs when lives = 0, so it should say Game over. Keep going belongs in the else part, so line 3 should be: say [Game over].
Q5
A — The if block needs a true or false condition. coins + 10 is a number, not a comparison. Line 1 should be: if <coins = 10> then.