Logical Operators

Logical Operators are used to perform basic logic gate operators like AND, OR, and NOT. The following table lists out all the logical operators in Dart programming.

OperatorSymbolExampleDescription
AND&&x&&yReturns logical AND gate operation between x and y inputs.
OR||x||yReturns logical OR gate operation between x and y inputs.
NOT!!xReturns logical NOT gate operation for x input signal.

Example

In the following program, we will take boolean values in variables x and y, and perform logical operations on these values using Dart Logical Operators.

main.dart

void main() {
    var x = true;
    var y = false;

    var andOutput = x && y;
    var orOutput = x || y;
    var notOutput = !x;

    print('x && y = $andOutput');
    print('x || y = $orOutput');
    print('!x = $notOutput');
}

Output

x && y = false
x || y = true
!x = false

Logical Operators Tutorials

The following tutorials cover each of the Arithmetic Operators in Dart, in detail with examples.

  • ANDDart Tutorial about logical AND operator, its syntax, truth table, and usage with examples. AND operator is used when we need to check if given two conditions must be met.
  • ORDart Tutorial about logical OR operator, its syntax, truth table, and usage with examples. OR operator is used when we need to check if at least one of the two given conditions must be met.
  • NOTDart Tutorial about logical NOT operator, its syntax, truth table, and usage with examples.

Conclusion

In this Dart Tutorial, we learned about all the Logical Operators in Dart programming, with examples.