Concept Explanation: Logical Expressions

Printer-friendly version

 

As long as the NXT is on a white board, it will run continuously until it runs into the first black line. While this is going on, the NXT can't do anything but what is included in the while code block. Let's say that we setup a wall around our board. We don't want the NXT to crash into the wall so we need to add a second condition to the while loop. The NXT should leave the while loop if it gets too close to a wall. This would result in the NXT stopping.

To have a conditional statement that has two conditions, we need to use a logical statement like "AND". This logical statement will return a TRUE only when both conditions are TRUE. we use the double ampersand "&&" to designate an AND statement. By separating the two conditions with an double ampersand, we change the behavior of the NXT. Now if a line or a wall is detected, the NXT will stop.