What is a BOOLEAN? — Programming theory

Definition of BOOLEAN

A BOOLEAN is a type of prim­i­tive vari­able that is char­ac­ter­ized by being able to be in only two states, "true" or "false". The name of this vari­able is due to the math­e­mati­cian George Boole who cre­at­ed Boolean alge­bra, which is the basis of all dig­i­tal operations.

Here is a more detailed arti­cle about what are vari­ables in pro­gram­ming and the dif­fer­ent types of vari­ables.


Syntax of a BOOLEAN VARIABLE in C#

To define a boolean vari­able in C# lan­guage, in Uni­ty, we use the word "bool" and then we indi­cate the name of the vari­able, for exam­ple as follows:

bool aBoolean = false;

Applications of a BOOLEAN variable

The most impor­tant appli­ca­tion of a Boolean vari­able is in deci­sion mak­ing to con­trol the flow of a pro­gram, an IF STATEMENT is a con­trol struc­ture that allows us to make deci­sions based on a boolean con­di­tion. If the con­di­tion indi­cat­ed in the IF state­ment is true, the pro­gram will exe­cute a cer­tain region of code, if the con­di­tion is false we can make it exe­cute a dif­fer­ent region of code.

A WHILE loop is a repet­i­tive con­trol struc­ture that will exe­cute a series of instruc­tions that we indi­cate and when fin­ished it will repeat those instruc­tions, this process will con­tin­ue as long as the indi­cat­ed con­di­tion remains true, when the con­di­tion changes to false the pro­gram flow will exit the loop.

Using Boolean vari­ables and log­i­cal oper­a­tors we can rep­re­sent any log­i­cal expres­sion we need, these expres­sions can use mul­ti­ple vari­ables and can be gen­er­at­ed from a truth table.

In gen­er­al, any­thing that is enabled/disabled states in Uni­ty is rep­re­sent­ed by a boolean vari­able that is some­times read­able and writable or some­times read-only. Two exam­ples are the enabled state of a GameOb­ject from the hier­ar­chy and the enabled state of a script assigned to a GameOb­ject. You can make an object dis­ap­pear from the scene, sim­ply by chang­ing its enable state, this video shows how to enable and dis­able GameOb­jects from the scene and this one shows how to enable and dis­able com­po­nents assigned to GameOb­jects.

Scroll to Top
Secured By miniOrange