AdvertisementYour brand could be hereYour brand hereOn every Darslab page · students, parents and teachersinfo@darslab.comAsk for pricesPricesinfo@darslab.com
☰ Year plan · Computing

Selection in Scratch

Week 14 · Unit 6: Be an animator · 3 lessons
2

Predict the outcome

Computing 5: Unit 6, pp. 70–85
GoalPredict what a program with an if … then block does when the condition is true and when it is false.
New words
outcome · what a program does when it runspredict · to say what will happen before the program runstrue · the condition is correct at the moment that it is checkedfalse · the condition is not correct at the moment that it is checked
Explanation

A program with an if … then block has two possible outcomes. If the condition is true, the conclusion is carried out. If the condition is false, the conclusion is skipped. To predict the outcome, work through the blocks one at a time, just as the computer does. Each time that the if block is reached, check its condition. A forever block makes the program come back to the if block again and again. Write down what happens at each pass. Then run the program and compare the result with your prediction.

Penguinwhenclickedgo to x:-100y:0Penguinwhenright arrowkey pressedmove50stepssayLunch!for2secondsiftouchingFish?then
Worked examples
PressPenguin’s x after movingTouching the Fish?Outcome
1-50nonothing
20nonothing
350nonothing
4100yessays Lunch!
The Fish stays at x: 100, y: 0. The sprites are small, so they touch only when they are at the same spot. Each press of the right arrow key moves the Penguin 50 steps. The Penguin says ‘Lunch!’ only on press 4.
Liftwhenclickedwait1secondschange y by10ifkeyspacepressed?thenforever
A forever loop with a wait block checks the condition once every second. The sprite moves up only at the checks where the key is held down.
Second123456
Space key held?yesyesyesnoyesno
y after the check102030304040
The sprite starts at y: 0. The key is held at four of the six checks, so the sprite moves up 4 times and ends at y: 40.
Class activity

Track game (pairs). Draw a track of 10 squares in a row and number them 1 to 10. Put a counter on square 1. Rule A: each ‘press’ moves the counter 3 squares forward. Rule B: if the counter is on square 7, then say ‘Treat!’. Before you play, predict on which press the counter says ‘Treat!’. Play it and check. Now change rule A to 2 squares, and then to 4 squares. Predict first each time. What happens with 4 squares, and why?

Practice
1
The Goat starts at x: -90 and moves 30 steps for each press of the up arrow key. The Gate is at x: 90, and they touch only on the same spot. After which press does the Goat say ‘Baa!’?
Goatwhenup arrowkey pressedmove30stepssayBaa!for1secondsiftouchingGate?then
2
The Sheep starts at x: -90 and moves 40 steps for each press. The Gate is at x: 100. Will the Sheep ever say ‘Baa!’? Explain.
Press12345
Sheep’s x?????
3
A forever block checks every second. The key is held at checks 1, 3 and 4 and not held at checks 2 and 5. Each true check changes x by 15. The sprite starts at x: 0. Where is it after the 5 checks?
Check12345
Key held?yesnoyesyesno
4
Write the two outcomes of this program.
whenclickedwait1secondsplay soundPopuntil doneiftouchingNet?then