General and Web Programming Fundamentals
  • Introduction
  • Program creation and design
    • Program design
      • Algorithms
      • Pseudocode
    • Programming conventions
    • Writing programs
      • Source code editors
      • Integrated Development Environments
      • Code repositories/Version control
      • Compilers/Interpreters
  • Programming Fundamentals
    • Operators
      • Arithmetic
      • Logical
      • Assignment
    • Constants and Variables
    • Datatypes
      • Primitive Datatypes
        • Character
        • Integer
        • Boolean
        • Floating point
        • Nothing (Null)
      • Composite Datatypes
        • Arrays
        • Strings
        • Classes
        • Structs
      • Literals
    • Data structures
      • Lists
      • Queues
      • Stacks
      • Map/dictionary
      • Trees
      • Graphs
    • Control structures
      • Selection (Conditional)
        • If/Else
        • Ternary
        • Switch
      • Iteration (Loops)
        • For loops
        • While loops
        • Do-While loops
        • For-Each loops
    • Functions
      • Parameters and arguments
      • Lambda expressions
      • Higher Order Functions
    • Space and Time
    • Scope
    • Standard libraries
  • Programming Paradigms
    • Procedural (Imperative) Programming
    • Object-oriented programming
    • Functional Programming
    • Declarative Programming
    • Event Driven programming
  • Programming Languages
    • Short history of programming
    • Low-level programming languages
    • High-level programming languages
  • Web Development
    • What is the web?
      • Web browsers (clients)
      • Webservers (serving web pages)
      • W3C
    • Markup languages
      • HTML
        • HTML Tags
      • Cascading Style Sheets (CSS)
        • CSS Properties
      • XML
      • Markdown
    • Scripting Languages
      • JavaScript
      • TypeScript
    • JSON
    • JavaScript Frameworks
  • Acknowledgements
    • About the author(s)
  • License
Powered by GitBook
On this page

Was this helpful?

Export as PDF
  1. Programming Fundamentals
  2. Datatypes
  3. Primitive Datatypes

Boolean

The Boolean data type, named after the mathematician George Boole, is a fundamental concept in computer programming and computer science. It represents a logical entity that can have one of two values: true or false. These values are used to perform logical operations, most commonly in conditional statements and loops, allowing for the control flow of a program to be altered based on certain conditions.

Characteristics of the Boolean Data Type:

  • Binary Values: A Boolean variable can only hold one of two possible values: true or false. This binary nature makes it ideal for decisions that are essentially yes/no or on/off.

  • Logical Operations: Booleans are primarily used with logical operators such as AND (&& or AND), OR (|| or OR), NOT (! or NOT), which operate on Boolean values to produce a Boolean result. These operations are foundational to constructing complex conditions in programming.

  • Control Structures: In programming, control structures like if statements, while loops, and for loops often rely on Boolean expressions to determine the flow of execution. For example, an if statement might execute a block of code only if a certain Boolean expression evaluates to true.

  • Storage Efficiency: Because Boolean values are so simple, they require very little storage space, typically one bit. However, the actual size of a Boolean data type can depend on the programming language and its implementation.

Usage in Different Programming Languages:

While the concept of Boolean remains consistent across programming languages, the implementation and syntax can vary:

  • In Python: Booleans are written as True and False, with capital 'T' and 'F'.

  • In Java and C++: Booleans are declared with the boolean keyword, and the values are true and false, all in lowercase.

  • In JavaScript: Similar to Java and C++, but with the flexibility of being dynamically typed.

Example in Python:

is_raining = True
if is_raining:
    print("Don't forget to bring an umbrella!")

In this Python example, is_raining is a Boolean variable that determines whether the message is printed based on its truth value.

PreviousIntegerNextFloating point

Last updated 1 year ago

Was this helpful?