What is a BOOLEAN? – Programming theory

Definition of BOOLEAN

A BOOLEAN is a type of primitive variable that is characterized by being able to be in only two states, “true” or “false”. The name of this variable is due to the mathematician George Boole who created Boolean algebra, which is the basis of all digital operations.

Here is a more detailed article about what are variables in programming and the different types of variables.

Syntax of a BOOLEAN VARIABLE in C#

To define a boolean variable in C# language, in Unity, we use the word “bool” and then we indicate the name of the variable, for example as follows:

bool aBoolean = false;

Applications of a BOOLEAN variable

The most important application of a Boolean variable is in decision making to control the flow of a program, an IF STATEMENT is a control structure that allows us to make decisions based on a boolean condition. If the condition indicated in the IF statement is true, the program will execute a certain region of code, if the condition is false we can make it execute a different region of code.

A WHILE loop is a repetitive control structure that will execute a series of instructions that we indicate and when finished it will repeat those instructions, this process will continue as long as the indicated condition remains true, when the condition changes to false the program flow will exit the loop.

Using Boolean variables and logical operators we can represent any logical expression we need, these expressions can use multiple variables and can be generated from a truth table.

In general, anything that is enabled/disabled states in Unity is represented by a boolean variable that is sometimes readable and writable or sometimes read-only. Two examples are the enabled state of a GameObject from the hierarchy and the enabled state of a script assigned to a GameObject. You can make an object disappear from the scene, simply by changing its enable state, this video shows how to enable and disable GameObjects from the scene and this one shows how to enable and disable components assigned to GameObjects.

Scroll to Top
Secured By miniOrange