How to Use a Boolean OR Operator in VEX C++

Get more with VEXcode
We recommend you transition to our new software. VEXcode has both block-based and text-based options, that work on Chromebooks, iPads, Android tablets, Windows and Macs. Visit code.vex.com for more details on how to download VEXcode.
VEX Coding studio has been discontinued and is no longer available for download. Already downloaded? The program will continue to function but will no longer be supported.
Users who transition to VEXcode can migrate their C++/C++ Pro projects to VEXcode Text by following this article.

Use the boolean operator OR to include at least one of the possible conditions

  • Use the OR operator || to have the program check if either of two conditions, or any of multiple conditions, is true. 

NOTE: In the example above, the if statement is actioned if the Bumper Switch is pressed or the V5 Robot Brain's screen is pressed.

NOTE: It is easier to use boolean operators if the outcomes of conditions are considered. Logical truth tables like those below are used to track input conditions and output behaviors.

Code that can be copied and pasted:

#include "robot-config.h"   

int main() {          
    //The robot moves forward unless the Bumper Switch or the Screen is pressed.         
    while(true){         
        if(Bumper.pressing()==true || Brain.Screen.pressing()==true){             
            LeftMotor.stop();             
            RightMotor.stop();         
        }else{             
            LeftMotor.spin(directionType::fwd);             
            RightMotor.spin(directionType::fwd);         
        }     
    } 
}