Boolean Type - bool
The boolean is a simple binary value that may be either true
or false
. The
value can be also represented as 0 (false
) and 1 (true
).
Booleans are commonly used in conditional statements and loops, where relational expressions and logical expressions are used to determine the flow of the program, and implement complex logic.
Examples
Simple bool variable definitions
Comparison of two numbers
Using a boolean as a number
Using a boolean inside an if statement
- External boolean variable:
- Direct boolean expression (relational expressions or logical expressions):
Using a boolean inside a while loop
- External boolean variable:
- Direct boolean expression (relational expressions or logical expressions):