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
These are the only two Boolean values.
Boolean from comparison
Comparison operators produce Boolean results.
Result → true
Result → false
Boolean in conditions
Booleans are often used inside if statements.
The expression age >= 18 returns a Boolean value.
Logical operators with Boolean
Booleans can be combined using logical operators.
This allows more complex decision-making.
Boolean variables
You can store Boolean values in variables.
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
- What is Condition?
- What is Operator?
- What is Expression?
Source
Simplified from general programming documentation and Wikipedia.