Raspberry Realize Blink with While loop
In this project, we will use the while-loop to achieve the effect of a continuously flashing LED.
Write a Program
Using the while loop, we can easily make the program repeat indefinitely. We only need to change the “for i in range(10)" in the program to “while True":
The “while True" is a use of while-loop statement. Unlike a general while-loop that only executes the loop when a certain condition is met, this “while True" is an indefinite loop statement, which means that the program will be executed repeatedly and continuously until it is artificially terminated.
The complete code is as follows:
Click the “run" button again, and the LED connected to the Shield starts flashing. Unless the process is artificially stopped, the LED will continue to flash.