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

Term 1 review

Week 11 · Review: Term 1 · 3 lessons
1

Loops and animation

Computing 4: Units 1–4, pp. 8–61
GoalRemember how forever and repeat loops, comments, costumes and coordinates work in an animation.
New words
loop · a set of instructions that runs again and againcomment · a note in a program that the computer does not runcoordinates · the x and y numbers that give a place on the stage
Explanation

A loop saves us from writing the same blocks again and again. A forever block repeats its blocks until someone stops the program, and nothing can be attached under it. A repeat block runs its blocks a set number of times and then the script carries on. When an algorithm says “repeat these steps three more times”, the repeat block gets the number 4, because the steps ran once already. Costumes let a sprite change its picture, and the stage uses x and y numbers to say where a sprite is. A comment is only a note for people. It never changes what the sprite does.

foreverrepeat (n)
How many times?never stops by itselfexactly n times
Blocks underneath?no room for anyyes, they run afterwards
Good fora scene that runs on and ona job with a set count
Worked examples
x 240−240y 180−180startend
A dolphin sprite starts at x: −100, y: −40. The script runs repeat (3) with “change x by (50)”, “change y by (20)” and “wait (0.5) seconds”. Each trip moves it 50 right and 20 up, so it passes (−50, −20) and (0, 0) and ends at (50, 20) after 1.5 seconds.
whenclickedturn ↻30degreeswait1secondsrepeat6
An algorithm says: 1 Start. 2 Turn 30 degrees. 3 Wait 1 second. 4 Repeat steps 2 and 3 five more times. 5 Stop. The steps run 1 + 5 = 6 times, so the script has repeat (6). The sprite turns 6 × 30 = 180 degrees, so it ends facing the opposite way and the script takes 6 seconds.
BlockComment saysSprite really
move (20) stepsmove 5 stepsmoves 20 steps
wait (3) secondsshort pausewaits 3 seconds
repeat (2)run six timesruns two times
A comment is a note, not a command. Look at what each block really does, not at what the comment says.
Class activity

Animation flip book (with family): fold a small stack of paper and draw a ball that is a little higher on every page, five pages in all. Flip through the pages. Which page of your book is the “next costume”? Now write a script for it on paper that uses a repeat block and a wait. If you go on flipping forever, which block is that? Write one comment on your script and say who it helps.

Practice
1
A sprite starts at x: 0, y: 0 and runs the script. Where is it at the end?
whenclickedgo to x:0y:0change x by-20change y by10repeat4
2
An algorithm says “Repeat steps 2 and 3 seven more times”. Which number goes in the repeat block?
3
A comment says “move 50 steps” but the block says “move (5) steps”. How far does the sprite move? What should you fix?
whenclickedmove5steps
4
A sprite has 3 costumes and starts on costume 2. Which costume does it wear after “next costume” has run 5 times?