Boolean

Programming Fundamentals
definition

Also known as: bool, true/false, logical value

Grade 6-8

View on concept map

A data type representing a logical value that can only be true or false—nothing else. Booleans drive all program logic — conditionals, loops, and comparisons all produce or consume boolean values.

Definition

A data type representing a logical value that can only be true or false—nothing else. Booleans are produced by comparison operators (==, <, >, !=) and consumed by control structures (if-statements, while-loops) to make decisions.

💡 Intuition

A boolean is a yes/no answer. Is the user logged in? True or false. Is the number positive? True or false.

🎯 Core Idea

Booleans are the language of decisions. Every if-statement evaluates a boolean condition.

Example

is_raining = True. has_umbrella = False. should_go_outside = (not is_raining) or has_umbrella gives False.

🌟 Why It Matters

Booleans drive all program logic — conditionals, loops, and comparisons all produce or consume boolean values. Every decision a program makes ultimately reduces to a boolean: should this code run? Should the loop continue? Does this match the search criteria?

💭 Hint When Stuck

When working with booleans, remember that comparison operators like ==, <, and > return boolean values. You can combine booleans using AND, OR, and NOT. Be careful with 'truthy' and 'falsy' values—in many languages, 0, empty strings, and null are treated as False in conditions.

Formal View

The boolean type is the set \mathbb{B} = \{\text{true}, \text{false}\} with operations \land (AND), \lor (OR), and \lnot (NOT), forming a Boolean algebra.

🚧 Common Stuck Point

0, empty string, None/null, and empty lists are often 'falsy' — they act like False in conditions even though they're not boolean.

⚠️ Common Mistakes

  • Comparing a boolean to True explicitly (if x == True) instead of using it directly (if x)
  • Not understanding truthy/falsy values—0, empty string, None, and empty list evaluate as False in conditions
  • Using assignment (=) instead of equality (==) in a boolean expression, which changes the variable instead of testing it

Frequently Asked Questions

What is Boolean in CS Thinking?

A data type representing a logical value that can only be true or false—nothing else. Booleans are produced by comparison operators (==, <, >, !=) and consumed by control structures (if-statements, while-loops) to make decisions.

When do you use Boolean?

When working with booleans, remember that comparison operators like ==, <, and > return boolean values. You can combine booleans using AND, OR, and NOT. Be careful with 'truthy' and 'falsy' values—in many languages, 0, empty strings, and null are treated as False in conditions.

What do students usually get wrong about Boolean?

0, empty string, None/null, and empty lists are often 'falsy' — they act like False in conditions even though they're not boolean.

How Boolean Connects to Other Ideas

To understand boolean, you should first be comfortable with assignment and data types. Once you have a solid grasp of boolean, you can move on to boolean logic and selection.