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

Short programs and resets

Week 2 · Unit 1: Making programs clear · 3 lessons
1

Join repeated blocks

Computing 3: Unit 1, pp. 8–27
GoalMake a Scratch program shorter by joining blocks that repeat and removing blocks that do nothing.
New words
block · a piece of code that you snap into a programsprite · a character or object that follows a Scratch programconcise · short, with nothing extra
Explanation

A Scratch program is a stack of blocks. Sometimes the same block appears again and again, side by side. “change x by (35)” twice moves the sprite 70 steps right, so one block “change x by (70)” does the same job. We can also take out a block that does nothing, such as “change size by (0)”. The shorter program is more concise, and the sprite ends up in just the same place. Always count the blocks before and after to see how many you saved.

Program A (7 blocks)whenclickedchange x by35change x by35change size by-5change size by-5change size by0sayBubble!for2secondsProgram B (4 blocks)whenclickedchange x by70change size by-10sayBubble!for2seconds
Worked examples
Program AProgram B
x at the end−100 + 35 + 35 = −30−100 + 70 = −30
size at the end100 − 5 − 5 = 90100 − 10 = 90
blocks74
A fish starts at x: −100 with size 100. In program A it moves 35 right twice and shrinks by 5 twice. In program B it moves 70 right once and shrinks by 10 once. Both end at x: −30 and size 90. Program B has 3 fewer blocks.
whenclickedchange y by30wait1secondschange y by30
These blocks cannot be joined. There is a wait block between them, so the sprite pauses in the middle of its climb. Joining them would remove the pause and change what the sprite does.
whenclickedturn ↻0degreesmove40stepsmove0steps
In this program the red blocks do nothing, because turning by 0 degrees and moving by 0 steps change nothing. We can remove them. Only one useful block is left.
Class activity

Block cards (with a friend): write each block of a program on its own small card, for example “change x by 20”, “change x by 20”, “say Hello for 2 seconds”. Lay the cards in order. Count them. Now join cards that are the same and side by side, and take away any card that does nothing. Count again. Do both stacks make the sprite end in the same place? If you have a computer or tablet, build both programs in Scratch and compare.

Practice
1
Make this program more concise. How many blocks does your new program have?
whenclickedchange y by-20change y by-20change y by-20wait1secondschange size by10change size by10
2
Two “change x by (25)” blocks are side by side. Which one block can replace them?
whenclickedchange x by25change x by25
3
Can the two “change x by (10)” blocks be joined into one? Explain.
whenclickedchange x by10sayHi!for1secondschange x by10
4
Give two reasons why a concise program is better.