Remember: An if-else asks one question and then does exactly one of two paths: then when the answer is yes, else when it is no.
Read and answer
Read the story, then answer.
Bo at the bridgeKai was thirsty up in his treehouse, so Bo carried a jug of lemonade along the garden path. Kai's rule on a card said: if the bridge is clear, cross it. But a branch lay across the bridge, so the if was false and the rule said nothing at all. Bo stood at the edge and waited. Kai laughed, because Bo had done just what the rule said. An if on its own is not enough, said Kai. We need an else. The new rule said: if the bridge is clear, cross it, else hop over the stones. Now exactly one of the two paths would happen. The next day the bridge was clear, so Bo crossed it and skipped the stones.
1
Why did Bo stand still at the stream?
🌉The bridge was blocked and his rule had no else😴He was tired🫗The jug was empty
2
An if-else can run both of its paths at the same time.
TrueFalse
3
When the answer to the question is no, the part runs.
thenelseboth
4
Today the bridge is not clear. Which line of the program does Bo skip?
cross the bridgehop over the stonesneither line
5
After the two paths, the program carries on from where they meet.
TrueFalse
6
Which rule has an else, so it always does one of two things?
if it rains, take an umbrellaif it is sunny, walk to school, else take an umbrellaif the bell rings, open the door
Rules, order and fix
7
Join each part of the rule to Bo's story.
1the question
2the then part
3the else part
Ais the bridge clear?
Bhop over the stones
Ccross the bridge
8
The bridge is not clear today. Put what Bo does in order.
Bo hops over the stones
Bo asks: is the bridge clear?
Bo skips the bridge path
The answer is no
9
Look at the table. On how many of these days does Bo hop over the stones?
421
10
Bo hops over the stones even when the bridge is clear. What is the mix-up to fix?
Put the stones line under an else, so only one path runsTake out the bridge lineAdd a second bridge line
11
Bo meets two forks in a row, and each one is an if-else. How many paths does he take in all?
412
12
Write an if-else rule for your morning, with a question, a then part and an else part.
Scan the code at the top to mark this sheet on screenTake a photo of your answers or type them. It is marked for you automatically, and your score is kept.
Answer key · Set A
Kai's lemonade rule
1The bridge was blocked and his rule had no else The rule only said what to do when the bridge was clear. With a branch across it, the rule said nothing at all.
2False An if-else picks exactly one of two paths, never both and never neither.
3else Else covers the other case, when the answer is no.
4cross the bridge The question says no, so Bo skips the bridge path and does the else part, the stones.
5True Whichever path Bo took, he ended up at the same treehouse.
6if it is sunny, walk to school, else take an umbrella Only the middle rule has an else. The other two do nothing at all when the answer is no.
71-A, 2-C, 3-B The question is asked first. Yes does the then part, and no does the else part.
84, 1, 3, 2 He asks, the answer is no, so the else part runs and the stones are used.
92 Bo hops over the stones when the bridge is not clear. That is Tuesday and Wednesday, so 2 days.
10Put the stones line under an else, so only one path runs Without an else, the stones line runs every time. With else, exactly one path runs.
112 Each if-else picks exactly one path, so two forks make two paths.
12Your own words: a grown-up reads it.
Mark each answer, count the right ones and write the score on the sheet.