In this tutorial you will learn about the Dart Relational operators and its application with practical example.
Dart Relational Operators
Relational Operators are used evaluate a comparison between two operands. The result of a relational operation is a Boolean value that can only be true or false. Relational Operators are also referred as Comparison operators.
Let variable a holds 20 and variable b holds 10, then −
Operator | Description | Example |
---|---|---|
> |
greater than |
a>b returns TRUE |
< |
Less than |
a<b returns FALSE |
>= |
greater than or equal to |
a>=b returns TRUE |
<= |
less than or equal to |
a<=b returns FALSE |
== |
is equal to |
a==b returns FALSE |
!= |
not equal to |
a!=b returns TRUE |
Example:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
void main() { var n1 = 20; var n2 = 10; print("W3Adda - Dart Relational Operators"); var res = n1>n2; print('n1 greater than n2 : ' +res.toString()); res = n1<n2; print('n1 lesser than n2 : ' +res.toString()); res = n1 >= n2; print('n1 greater than or equal to n2 : ' +res.toString()); res = n1 <= n2; print('n1 lesser than or equal to n2 : ' +res.toString()); res = n1 != n2; print('n1 not equal to n2 : ' +res.toString()); res = n1 == n2; print('n1 equal to n2 : ' +res.toString()); } |
When you run the above Dart program, you will see following output.
Output:-