If you’ve watched some videos about variables and conditional statements, you might have wondered what it means to have a variable of type boolean. A variable is a type like an integer, and it is a name that we might give an initial value. A variable of type boolean only has two possible values: true or false.
A conditional statement is an expression that evaluates to true or false, and a boolean variable evaluates to true or false as well. For example, if we have a boolean variable called ‘going’ that is false, we won’t execute the code because it’s not going. But if we change its value to true, the code will be executed.
We can use boolean variables in many ways, such as in an example where we want a circle to start moving only when we click the mouse. To do that, we can make up our own variable like ‘going’ and set it to false. Then, we can change the value of ‘going’ to true when we click the mouse, and the circle will start moving.
But what if we want ‘going’ to become false if it was already true? We can implement a neat little trick where we set ‘going’ to false if it’s already true, and set it to true if it’s false. This can be made shorter by using the exclamation point to say ‘not going’.
In conclusion, a variable of type boolean only has two possible values, true or false. We can use boolean variables with conditional statements to execute code based on their value, and we can implement tricks to make our code shorter and more efficient.