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

Loops and light shows

Week 29 · Unit 12: Be an artist · 3 lessons
2

Loops that never stop

Computing 4: Unit 12, pp. 168–179
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.

LoopHow many roundsHow it ends
repeat (5) timesexactly 5by itself, after round 5
foreverno limitonly when we stop it
Worked examples
show ledspause (ms)500show ledspause (ms)500show ledspause (ms)500show ledspause (ms)500forever
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.
ArrowOn fromUntil
North0 s0.5 s
East0.5 s1.0 s
South1.0 s1.5 s
West1.5 s2.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.
show ledspause (ms)400show ledspause (ms)400forever
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?
TimeFull cyclesTime left overArrow
7.3 s???
2
Using the twinkling star, which star is on at 5.5 seconds?
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?
4
In 10 seconds, how many times does the East arrow come on in the arrow spinner?
ABeast arrow