
Menu
Historical Overview
Definitions
Different names
Operators
Precedence rules
Truth Tables
Examples of Boolean Expressions
Purpose
Usage examples
Quiz
|
Usage Examples
Boolean expressions can be used like a flag. For example
we want to keep track of a certain value or condition,
when it is fulfilled we can "flag" it true, and execute
some other code that takes care of this situation.
Boolean value is usually returned by primitives provided
by the language. For Example is the list empty? Do we
have more to read from a file? Etc.
We also get a Boolean value if we check the arithmetic
expressions. For example a>0 will return true if a is greater than 0
any negative value of a will make the expression evaluate to false.
Of course this can be used in control of flow execution or as a IF
control statement.
Example 1
Example 2
Example 3
|