In this tutorial you will learn about the Dart Logical operators and its application with practical example.
Dart Logical Operators
Logical operators are used to combine expressions with conditional statements using logical (AND,OR,NOT) operators, which results in true or false. Let variable a holds true or 1 and variable b holds false or 0, then −
Operator | Name | Description | Example |
---|---|---|---|
&& |
Logical AND |
return true if all expression are true |
(a && b) returns false |
|| |
Logical OR |
return true if any expression is true |
(a || b) returns true |
! |
Logical NOT |
return complement of expression |
!a returns false |
Example:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
void main() { bool bool1 = true, bool2 = false; print("W3Adda - Dart Logical Operators"); var res = bool1 && bool2; //Logical AND print("bool1 && bool2 = " + res.toString()); res = bool1 || bool2; //Logical OR print("bool1 || bool2 = " + res.toString()); res = !(bool1 && bool2); //Logical Not print("!(bool1 && bool2) = " + res.toString()); } |
When you run the above Dart program, you will see following output.
Output:-