While

Repeat code while a Boolean condition is true.

while(true) {
}

The while loop has a condition that evaluates to a Boolean value.

The condition is tested before any code runs. Which means that if the condition is false, the code inside the loop doesn’t execute.

Example: diagonal line

The following example uses a while loop to make a diagonal line on the LED screen (points 0, 0, 1, 1, 2, 2, 3, 3, 4, 4).

input.onButtonEvent(Button.A, input.buttonEventValue(ButtonEvent.Down), () => {
    let index = 4;
    while(index >= 0) {
        led.plot(index, index);
        index--;
    }
})