Dart bool Data Type by Examples
In this tutorial, we learn how to use bool data type in Dart programming language.
How to declare a bool variable in Dart
Declare true value.
void main() {
bool value = true;
if(value) {
print("value is true");
} else {
print("value is false");
}
}
value is true
Declare false value.
void main() {
bool value = false;
if(value) {
print("value is true");
} else {
print("value is false");
}
}
value is false
Convert bool value into String in Dart
void main() {
bool value1 = true;
bool value2 = false;
print(value1.toString());
print(value2.toString());
}
true
false
Basic operators with bool in Dart
The and ( & )operator.
void main() {
if(true & false) {
print("true result");
} else {
print("false result");
}
}
false result
void main() {
if(true & true) {
print("true result");
} else {
print("false result");
}
}
true result
void main() {
if(false & false) {
print("true result");
} else {
print("false result");
}
}
false result
The exclusive or ( ^ ) operator.
void main() {
if(true^false) {
print("true result");
} else {
print("false result");
}
}
true result
void main() {
if(true^true) {
print("true result");
} else {
print("false result");
}
}
false result
void main() {
if(false^false) {
print("true result");
} else {
print("false result");
}
}
false result
The inclusive or ( | ) operator.
void main() {
if(true|false) {
print("true result");
} else {
print("false result");
}
}
true result
void main() {
if(true|true) {
print("true result");
} else {
print("false result");
}
}
true result
void main() {
if(false|false) {
print("true result");
} else {
print("false result");
}
}
false result
Happy Coding 😊
Related Articles
Dart integer Data Type by Examples
Dart double Data Type by Examples
Dart String Data Type by Examples