Learn creative coding writing simple programs

94. Boolean: true or false?

The boolean data type is often used for making decisions. A boolean variable can only have two different values: true and false. There are different ways of comparing values. We can test if a number is greater or smaller than another number, if they are equal, if they are different. In each case a value of true or false is returned. We can print this value, or store it in a variable of type boolean.
The same way numbers can be added, substracted and multiplied, boolean values (true and false) can be combined by using AND, OR and NOT. Imagine we have two boolean values called A and B. Each can be either true or false. A AND B is true only if both variables are true. A OR B is true if any of the two variables is true. When writing programs you don't write AND, OR or NOT. You use &&, || and ! instead. For example if(x > 10 && x < 20) { print("x is a number between 10 and 20"); }

Tags: boolean, true, false, and, or

Code editor

You can make changes to the code below. Then

Questions and comments

Try to stay close to the topic of this episode. Use the Processing forums for help with unrelated Processing projects (or hire me for help ;-)

To indicate that a word in your comment is code, use the `backtick`. Example
  Do `float` and `int` smell similar?
To highlight code blocks, use ```processing and ``` like this:
  void setup() {
    size(600, 600);