Concept Explanation: Booleans

Printer-friendly version

 

Our third major data type is called a Boolean. This data type deals with logic and is based in the binary language at the heart of every computer. Binary is defined as something "composed of two pieces or parts". Booleans are the same as in it only has two states: True or False. A Boolean can not have any other value.

While Booleans are important, you will rarely use them in programming. In the NXT environment, where we have ample memory space, we use integers instead. That doesn't means you can't or shouldn't use Booleans. If you want to use Booleans, use the following syntax:

  • bool MyVar = true; //Creates a Boolean and sets variable to true.
  • bool MyVar = false; //Sets variable to false.