Concept Explanation: If Statements

Printer-friendly version

 

The IF statement is the most basic logic command that all other logical structure is based on. This gives our NXT the ability to make choices based off of data. In a basic IF statement, a conditional statement determines if a block of code is executed or not. If the statement is TRUE, the block is executed, if the statement is FALSE, the block is skipped. Let's look at an example:

IF-Blockv2

In this case, the logical test of the light sensor determines if NXT is on white or not. If the NXT is on white, the NXT will invert the motorspeed value so it is negative. This will cause the NXT to move backwards when the motor values are set.