How to Use a Boolean NOT 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.

Add the boolean operator NOT to indicate the inverse of a condition

  • Use the NOT operator ! to indicate an inverted condition (i.e. true becomes false, false becomes true).

NOTE: In the example above, the while loop continues while the brain's screen is NOT pressed. If/when the screen is pressed, the program exits the loop and carries out the subsequent commands for displaying text and moving forward. 

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() {
    //Loop to have the robot stay stationary until the screen is pressed.
    while(!Brain.Screen.pressing()){
            LeftMotor.stop();
            RightMotor.stop();
        }
    Brain.Screen.print("I'm moving forward for 3 seconds!");
    LeftMotor.spin(directionType::fwd);
    RightMotor.spin(directionType::fwd);
    task::sleep(3000);
    LeftMotor.stop();
    RightMotor.stop();
}