You can also place one control structure (loop or decision statement) inside another; this is called nesting. Nesting can help you to create more complex programs.
For example, the code below has an if-else statement inside a while loop. This means that the if-else is repeated over and over until button A is pressed. The if-else statement sets the color of the tail lights based on the value of the distance sensor. When you run this code, the tail lights will change color as you move an object close to the Finch and away. When you press button A, the program will stop checking the if-else and move to the stopAll() command, turning the lights off.