Computers are excellent at carrying out the same or very similar tasks over and over again.
They do this extremely quickly and very precisely without making mistakes or getting tired.
E.g. Adding lots of thousands of numbers together, logging data from a sensor 100 times a second or endlessly moving a game sprite backwards and forwards across a computer screen.
Look at the lighthouse script above.
The forever loop is used to make the lighthouse flash by displaying a costume with a light for two seconds then a costume with no light for one second over and over again forever!
Q19. What does a forever loop do?
Limiting the number of loops or repeats
The Repeat and Repeat until blocks are used to repeat the code in the loop a fixed
number of times e.g. repeat 10 will repeat the code in the
loop 10 times.
Repeat until block will repeat the script inside the loop until
a condition has been met, such as 10 questions have been answered.
Sign into Scratch 3 - click on Create and find the Tutorial - Making a Chase Game.
Q20. Explain what effect the Scratch block, Change Y by -50 would have on the movement of a sprite.
When a program has a fault in the code and does not run as expected we say that it has a bug.
Study the cat's script below.
The cat should say 'Yum yum!' when it touches the apple.
The green flag has been clicked, the game is running, the cat is moving about but it does not say Yum Yum when it touches the apple?
There is a bug in the code.
What has gone wrong and how can we debug debug the code?
Q21. Explain what you would do to debug this script.