Math Fundamentals18 sections · 814 units
Open in Course

Boolean Variables

Storing true/false

You can store boolean values in variables: isLoggedIn = true or hasPermission = false. These variables track state in your program.

Boolean variables make code readable. Compare if (age >= 18 && hasID && !isBanned) to if (canEnter). The second version names the condition.

When debugging, boolean flags help you trace program state. Set found = false before a loop, then flip it to true when you find what you need. After the loop, check the flag to see what happened.