This program will show the numbers 0, 1, 2, 3, and 4 one after another on the LED screen.
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.
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).
Run part of the program the number of times you say.
Flash the heart icon on the screen 4 times.
Run part of the program for each element in a list.
Find the highest number in a list of numbers. Display the highest number on the screen.
Run part of the program in a loop continuously at a time interval.
If you want to run some code continuously, but on a time interval, then use an every loop. You set the amount of time that the loop waits before the code inside runs again. This is similar to a forever loop, in that it runs continuously, except that there’s a time interval set to wait on before the loop runs the next time. This loop is useful when you want some of a program’s code run on a schedule.
At every 200 milliseconds of time, check if either the A or B button is pressed. If so, show on the screen which one is pressed.
Run code depending on whether a boolean condition is true or false.
If the light level is < 100, this code sets the brightness to 255 when the button A is pressed:
Problem 1
Create a block code that will display the temperature in degrees Celsius when button A is pressed. Convert Celsius to Fahrenheit when button B is pressed. When Shaked it will display Cold if the temperature is 20 degrees Celcius and below, it will display Hot if temperature is higher than 26 degrees Celsius and display Normal if the temperature is 21 to 25 degrees Celsius.