GoalExplain the forever loop, find out which picture is on at any moment in a repeating show and say how to stop a loop.
New words
forever loop · a loop that never ends by itselfstop · to end a program that is runningcycle · one full round of a repeating show
Explanation
Sometimes we do not want the show to end. A night-light should keep going all night. The forever block is a loop with no count. In micro:bit blocks it is a block of its own, and it starts as soon as the board is switched on. When the last block inside has run, it goes back to the first block again. It never ends by itself. We can stop it by pressing the stop button in a simulator, or by taking the power away from the board, which a grown-up does. Because a forever show repeats, we can find out which picture is on at any time. Divide the time by the length of one cycle and look at the remainder.
Loop
How many rounds
How it ends
repeat (5) times
exactly 5
by itself, after round 5
forever
no limit
only when we stop it
Worked examples
An arrow spinner. It starts when the board is switched on. Each arrow is on for 500 ms. The cycle is North, East, South, West, which takes 2 seconds, and then it begins again.
Arrow
On from
Until
North
0 s
0.5 s
East
0.5 s
1.0 s
South
1.0 s
1.5 s
West
1.5 s
2.0 s
Which arrow is on at 5.2 seconds? Two seconds make a cycle, so 5.2 s is two full cycles (4 s) and 1.2 s more. In the cycle, 1.0 s to 1.5 s is the South arrow. The answer is the South arrow.
A twinkling star. The small star is on for 400 ms and the big star for 400 ms, so one cycle takes 0.8 seconds. Which star is on at 3.3 seconds? Four cycles make 3.2 s, and 3.3 − 3.2 = 0.1 s. That is in the first 0.4 s, so the small star is on.
Class activity
Spin the arrow (with family): one person is the spinner and the others call out a time, such as 3.4 seconds. The spinner faces North, East, South or West, 0.5 seconds each, going round clockwise. Everybody works out the facing direction for each time before the spinner answers. Who is quickest? Then change the length of each step and try again.
Practice
1
Using the arrow spinner of the lesson, which arrow is on at 7.3 seconds?
Time
Full cycles
Time left over
Arrow
7.3 s
?
?
?
South. 7.3 s is three cycles (6 s) and 1.3 s, and 1.0 s to 1.5 s is the South arrow.
2
Using the twinkling star, which star is on at 5.5 seconds?
The big star. Six cycles take 4.8 s, and 5.5 − 4.8 = 0.7 s. The big star is on from 0.4 s to 0.8 s.
3
A night-light must blink a heart all night with no end. Which loop block should it use, repeat (5) times or forever? Why?
The forever block. It never ends by itself, so the heart keeps blinking until somebody stops the program or takes away the power.
4
In 10 seconds, how many times does the East arrow come on in the arrow spinner?
5 times. One cycle takes 2 seconds, and 10 ÷ 2 = 5, and East comes on once in each cycle.