You have heard that everything with computers comes down to binary, or yes and no answers. That is true, and you can use that in your programs using Boolean values and logic operators. Boolean variables contain, and only contain, the values true or false. To determine a true or false response, there are a number of operators called logic operators that evaluate an equation as either true or false. You can then take that value and work with it or assign it to a Boolean variable.
Creating a Boolean Variable
Setting a Boolean variable using a literal is just one way that you can assign a value, but it isn’t the most flexible way. Instead, the use of logic operators tests a number of scenarios to determine if a test, or condition, is true or false, and then the result of that test is assigned to the Boolean variable as true or false values.
Boolean Logic Operators
Altering a Boolean Value
Combining Logic with Evaluations
Compound Logic Operators
Code Examples
The next page shows examples of capturing input from the user.
This code is also available in the following GitHub repo:
Example Boolean logic code