In this chapter, we will learn about dart booleans data types.
Dart Booleans
Boolean values represent boolean values, i.e. true and false.
The bool keyword is used to denote boolean values.
The syntax for writing a boolean value is:
bool variable_name = true/false;
For example,
bool isValue = true;
bool count = false;
Let’s see this in the program.
void main() {
bool isValue = true;
bool count = false;
print(isValue);
print(count);
}
Output
true
false
The boolean values are mostly used in decision making and for loop conditions as well.
For example,
void main() {
if(true) {
print("Something");
}
else
print("Other things.");
}
Output
Something
Comparison and Logical Operators give the result as boolean values. For example,
Greater than operator > returns true if the left operand is greater than right operand.
void main() {
print(6 > 4);
}
Output
true
Equal to operator returns true if both operands are equal.
void main() {
print( 9 == 9);
}
Output
true
Logical OR || returns true if either of the operands is true.
void main() {
print(true || false);
}
Output
true
In next chapter, We will learn about Dart Lists.