MakeCode Loops (Part 2)
Loops (Part 2)
However, there are not only "while loops", but also the so-called "for loops". In "for loops", the instructions are executed for a certain number of passes. In the following example, the for loop is initialized with the variable "index". After each pass, the variable index is increased. For a pass from 0 to 4, as specified here, this means a total of 5 passes in which the inner instructions are repeated.
In the next example we will show you a small example of how the for loop works. Here two for-loops with 8 passes each are run through to control all LEDs of the Joy-Car one after the other. The index variable of the loop is accessed directly to get and use the current pass value.