Logical Operator in Dart Programming



Logical operators in dart are used when we want to evaluate expressions by putting conditional statements in between them, which ultimately results in a Boolean value.

Logical operators are only applied on Boolean operands.

There are three types of logical operators that are present in Dart. In the table below all of them are mentioned along with their name and the result they produced when they are used on two Boolean operands.

Let's consider two Boolean variables named, x and y, with values true and false respectively.

Consider the table shown below −

Operator Name Description Result
&& Logical AND Returns true if all expressions are true x && y = false
|| Logical OR Returns true is any expression is true x || y = true
! Logical NOT Returns compliment of the expression !x = false

Let's make use of all the above mentioned logical operators in a Dart program.

Example

Consider the example shown below −

 Live Demo

void main(){
   var x = true, y = false;
   print("x && y is: ${x && y}");
   print("x || y is: ${x || y}");
   print("!x is: ${!x}");
}

Output

x && y is: false
x || y is: true
!x is: false
Updated on: 2021-05-21T13:09:07+05:30

232 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements