"On Start"
At the beginning, each project consists of two basic blocks. The "on start" block and the "forever" block. All instructions within these two blocks are executed by the program. However, the "on start" block is only executed once when you start your program.
The following program turns on the brake light when you start the micro:bit, then waits 2 seconds and turns off the brake light again.
"Forever"
The "forever" block, on the other hand, is executed over and over again. As soon as all commands and instructions, from top to bottom, have been processed in this block, the execution starts again from the beginning. Here you can for example permanently check the sensors and react to new events.
The following code builds on the example. First, the "on start" block is executed. In this block, the brake light is switched on again, then waited 2 seconds and then the brake light is switched off. Since the code does not end here, in contrast to the first example, we have added another pause of one second. After this pause, the program jumps from the "on start" block to the "forever" block. Now the light is switched on in an endless loop, wait 2 seconds, switch off the light, wait 2 seconds and then the code starts again from the beginning.