Concept Explanation: Wait for Condition

Printer-friendly version

One of the most common ways to use a while loop is as a wait command. This is better than a simple wait1sec command because you can wait for almost any condition to be met. In our sample program, we use a while loop to wait for the NXT to cross a line. We start by moving the NXT forward. We then trap the NXT in a while loop until a line is detected. We should leave this section blank, but it is generally a good idea to give yourself some feedback when you wait for a condition. Once the light sensor detects a line, the NXT will leave the while loop and run into our stop commands.