Dart Programming - Equality and Relational Operators



Equality and Relational Operators

Relational Operators tests or defines the kind of relationship between two entities. Relational operators return a Boolean value i.e. true/ false.

Assume the value of A is 10 and B is 20.

Operator Description Example
> Greater than (A > B) is False
< Lesser than (A < B) is True
>= Greater than or equal to (A >= B) is False
<= Lesser than or equal to (A <= B) is True
== Equality (A==B) is False
!= Not equal (A!=B) is True

Usage of Equality and Relational Operators

Example

The following example shows how you can use Equality and Relational operators in Dart −

void main() { 
   var num1 = 5; 
   var num2 = 9; 
   var res = num1>num2; 
   print('num1 greater than num2 ::  ' +res.toString()); 
   
   res = num1<num2; 
   print('num1 lesser than  num2 ::  ' +res.toString()); 
   
   res = num1 >= num2; 
   print('num1 greater than or equal to num2 ::  ' +res.toString()); 
   
   res = num1 <= num2; 
   print('num1 lesser than or equal to num2  ::  ' +res.toString()); 
   
   res = num1 != num2; 
   print('num1 not equal to num2 ::  ' +res.toString()); 
   
   res = num1 == num2; 
   print('num1 equal to num2 ::  ' +res.toString()); 
} 

Output

It will produce the following output

num1 greater than num2 ::  false 
num1 lesser than num2 ::  true 
num1 greater than or equal to num2 ::  false 
num1 lesser than or equal to num2  ::  true 
num1 not equal to num2 ::  true 
num1 equal to num2 ::  false 
dart_programming_operators.htm
Tutorix - AI Tutor
Advertisements