Skip to main content

Decision Making - Blocks-based

A person standing at a fork in the road with two arrows painted on the ground. The left arrow, labeled FALSE, points to the left, while the right arrow, labeled TRUE, points to the right. The person is positioned at the intersection of the two paths.
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. Using the same example scenario as above, you could program your robot to repeatedly check if its brain screen is pressed and drive forward when it is. The conditional statement in that project may read something similar to, "If the screen detects that it is pressed (TRUE), run the driving sequence." This statement does not mention any behavior if the condition is FALSE (the screen is not pressed) so the robot takes no action when FALSE. Conditional statements allow you to develop projects that have the robot behave differently depending on what it senses.

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

VEXcode V5 project begins with a When started block with a Forever block attached. Inside the forever block is an If then else block that reads If screen pressed, then drive forward. Else, stop driving.