Skip to main content

Decision Making

Standing at the base of a forked decision path. To the left is an arrow reading False and to the right an arrow reading True.
TRUE and FALSE paths

Decision Making

At their most basic level, programs are written to accomplish simple sequences of behavior. For example, you might want your robot to drive forward and also make some turns to reach a destination. But, what if you want your robot to wait for the right time to start driving forward and complete its route? That would require programming with conditional statements. You would use a conditional statement to define what the "right time to start" is within your project. Maybe the "right time" is after a button is pressed or when a sensor detects a specific level and then it starts driving. When you watch the robot's behavior, it will seem like it is deciding when to start driving but it's because you set the condition for when driving should start.

Conditional statements are powerful programming statements that use a boolean (TRUE or FALSE) condition and allow you to develop projects that have the robot behave differently depending on what it senses.

In the following example, if the Brain Up button is pressed (TRUE) the robot will drive forward. If the Brain Up button is not pressed (FALSE) the robot will stop driving. This shows the robot only driving forward when the Brain Up button is pressed, otherwise the robot stops.

VEXcode IQ project with a When started block and a forever block attached. Inside the forever block is an If then else block that reads If brain Up button pressed then drive forward, else, stop driving.