# What is boolean?

**URL:** https://discourse.processing.org/t/what-is-boolean/15675
**Category:** Beginners
**Created:** [November 21, 2019, 3:58am UTC](https://discourse.processing.org/t/what-is-boolean/15675 "2019-11-21T03:58:09Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![meow](https://avatars.discourse-cdn.com/v4/letter/m/c57346/32.png) [@meow](https://discourse.processing.org/u/meow)
#### Post date: [November 21, 2019, 3:58am UTC](https://discourse.processing.org/t/what-is-boolean/15675/1 "2019-11-21T03:58:09Z")

</div>

what is boolean and how do they work in processing

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [November 21, 2019, 4:08am UTC](https://discourse.processing.org/t/what-is-boolean/15675/2 "2019-11-21T04:08:41Z")

</div>

a variable can be of type

```auto
boolean diag = true; // false; // global setting if need diagnostic printing to console

```

and later in the program anywhere can use

```auto
if ( diag ) println(" functionname: variablename: "+variablename);

```

and when all your code is tested and no diagnostic needed, set it to false

* * *

also the result of any comparison will create a boolean value  
`( a == b ) `  
is true or false.

---

<div class="post-metadata">

### Author: ![meow](https://avatars.discourse-cdn.com/v4/letter/m/c57346/32.png) [@meow](https://discourse.processing.org/u/meow)
#### Post date: [November 21, 2019, 4:18am UTC](https://discourse.processing.org/t/what-is-boolean/15675/3 "2019-11-21T04:18:29Z")

</div>

can you talk about it in a more simpler way thanks

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [November 21, 2019, 4:22am UTC](https://discourse.processing.org/t/what-is-boolean/15675/4 "2019-11-21T04:22:45Z")

</div>

hmm, or you tell us in what context you ask that question,  
so we better understand what level you are on and how we should respond?

---

<div class="post-metadata">

### Author: ![meow](https://avatars.discourse-cdn.com/v4/letter/m/c57346/32.png) [@meow](https://discourse.processing.org/u/meow)
#### Post date: [November 21, 2019, 4:25am UTC](https://discourse.processing.org/t/what-is-boolean/15675/5 "2019-11-21T04:25:04Z")

</div>

talking in general in processing

---

<div class="post-metadata">

### Author: ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)
#### Post date: [November 21, 2019, 4:29am UTC](https://discourse.processing.org/t/what-is-boolean/15675/6 "2019-11-21T04:29:28Z")

</div>

A boolean is a type of primitive variable.

It can either be set to true or false. This is pretty much a binary variable (yes/no, on/off, true/false).

In other programming languagues it could also be represented by 0 and 1, but in Java (which Processing is built with) a boolean is represented only by true and false (So you can‘t set it in another way, unlike how you could do with char for example).

Also, booleans are pretty much the only Form of conditionals (if statements, switch statements and even for loops all are based on boolean values) :

```auto
if (isThisTrue) { //if the variable isThisTrue is true, the Code in the statement is executed. 
//Code to execute if condition is true

} else if (!isThisTrue) { // using ! negates the boolean value (!true == false, !false == true). 

}

for (int i = 0; i < 100; i++) { //the i < 100 part will be true while i < 100 and thus will repeat until then. 
}

```

---

<div class="post-metadata">

### Author: ![meow](https://avatars.discourse-cdn.com/v4/letter/m/c57346/32.png) [@meow](https://discourse.processing.org/u/meow)
#### Post date: [November 21, 2019, 4:33am UTC](https://discourse.processing.org/t/what-is-boolean/15675/7 "2019-11-21T04:33:55Z")

</div>

thanks alot that is simpler way to understand so what is string? and how is so different to boolean?

---

<div class="post-metadata">

### Author: ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)
#### Post date: [November 21, 2019, 4:41am UTC](https://discourse.processing.org/t/what-is-boolean/15675/8 "2019-11-21T04:41:46Z")

</div>

String is any Type of Text. The difference is pretty big.

```auto
boolean b = true/false; //this is all that boolean could ever be (true or false)
String s = „You can write any Type of Text Here“ // This is basically what a String is (String is a primitive too, at least in Java)

```

And a String is basically nothing Else then a char array :

```auto
char[] ca = [‚H‘, ‚e‘, ‚l‘, ‚l‘, ‚o‘];
String s = „Hello“;
//A String is basically made up of a char[]. So
s.getCharAt(3); // would return L (using capital L to make clear that it‘s L)
ca[3]; // is also L

```

---

<div class="post-metadata">

### Author: ![meow](https://avatars.discourse-cdn.com/v4/letter/m/c57346/32.png) [@meow](https://discourse.processing.org/u/meow)
#### Post date: [November 21, 2019, 6:32am UTC](https://discourse.processing.org/t/what-is-boolean/15675/9 "2019-11-21T06:32:37Z")

</div>

> [@Lexyth](#):
>
> if (isThisTrue) { //if the variable isThisTrue is true, the Code in the statement is executed. //Code to execute if condition is true } else if (!isThisTrue) { // using ! negates the boolean value (!true == false, !false == true). } for (int i = 0; i \< 100; i++) { //the i \< 100 part will be true while i \< 100 and thus will repeat until then. }

so its same as boolean

---

<div class="post-metadata">

### Author: ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)
#### Post date: [November 21, 2019, 6:46am UTC](https://discourse.processing.org/t/what-is-boolean/15675/10 "2019-11-21T06:46:31Z")

</div>

Yes. “boolean” is a also a string, because it is between quotation marks.  
Another example:.

```auto
boolean bln;
String txt = "I am a troll";
if (txt.length() == 12) {
  bln = true;
} else {
  bln = false;
}
println(txt+" that is "+bln);

```

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [November 21, 2019, 7:25am UTC](https://discourse.processing.org/t/what-is-boolean/15675/11 "2019-11-21T07:25:00Z")

</div>

```auto
String True = "true";
boolean False = true;
if ( boolean(True) == False ) println("@noel is wrong");

```

---

<div class="post-metadata">

### Author: ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)
#### Post date: [November 21, 2019, 8:09am UTC](https://discourse.processing.org/t/what-is-boolean/15675/12 "2019-11-21T08:09:41Z")

</div>

Interesting,learning while trolling.

```auto
int True = 5; 

try {
  println(boolean(True/0));
}
catch(Exception e) {
  println("Not a boolean afterall");
}

```

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [November 21, 2019, 12:43pm UTC](https://discourse.processing.org/t/what-is-boolean/15675/13 "2019-11-21T12:43:56Z")

</div>

> [@meow](#):
>
> so its same as boolean

What do you mean?

- `isThisTrue` is a boolean

- String is not

See reference for all of this

---

<div class="post-metadata">

### Author: ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)
#### Post date: [November 21, 2019, 10:40pm UTC](https://discourse.processing.org/t/what-is-boolean/15675/14 "2019-11-21T22:40:52Z")

</div>

How did you come to the conclusion that it‘s the same?

There‘s a big difference, as i said.  
Boolean can ONLY be true or false. And true or false are not Strings, so this doesn‘t work :

```auto
String a = „true“;
boolean b = a; // this does not work. 
boolean b = boolean(a); //apparently you can do this, but this is still not a String being read as a boolean!
// It can be basically seen as : 
boolean boolean(String s) {
   if (s.equals(„true“)) {
      return true;
   } else if (s.equals(„false“)) {
      return false;
   } else {
      return null;
   }
}

```
