Boolean

A Boolean is a data type that can have only two values:  true or false.

It is used to represent logical conditions.

Why Boolean is important

Boolean values allow programs to:

  • Make decisions

  • Control conditions
  • Run loops
  • Compare values

Almost every program depends on Boolean logic.

Simple examples

true false

These are the only two Boolean values.

Boolean from comparison

Comparison operators produce Boolean results.

5 > 3

Result → true

10 == 7

Result → false

Boolean in conditions

Booleans are often used inside if statements.

if (age >= 18) { print("Adult") }

The expression age >= 18 returns a Boolean value.

Logical operators with Boolean

Booleans can be combined using logical operators.

true AND false → false true OR false → true NOT true → false

This allows more complex decision-making.

Boolean variables

You can store Boolean values in variables.

isLoggedIn = true

Now the variable represents a logical state.

Why learning Boolean matters

Understanding Boolean helps you:

  • Write conditions
  • Control program flow
  • Build logical expressions
  • Create interactive programs

Boolean logic is the foundation of decision-making in programming.

Simple example

Think of a light switch:

  • On → true
  • Off → false

That is Boolean logic in real life.

Related terms

Source

Simplified from general programming documentation and Wikipedia.

Nach oben scrollen