×

Dart Equality and Relational Operators

Dart provides the functionality of checking the relationship between the values or values within the variables.

These operators return the resultant value as Boolean, i.e., either ‘true’ or ‘false’.

Some important points to remember

  1. All these equality and relational operators are binary operators.
  2. The general structure of these equality and relational operator is similar to other binary operators :

                         Operand operator Operand
         Operands refer to the values and Operator is the symbol that instructs the             compiler about the function to be performed on the operands.

  1. In the case of strings, they are said to be equal only if these two strings contain the same character sequence.

List of Equality and Relational Operator

Let us consider the following table that contains the list of all the equality and relational operators in Dart.

For the following table, Consider A = 35, and B = 20

Operator

Operator Name

Operator Description

Example

> 

Greater than

This operator checks which operand is bigger and gives the result as a Boolean expression.

( A > B ) will return False

< 

Lesser than

This operator checks which operand is smaller and gives the result as a Boolean expression.

( A < B ) will return True

>=

Greater than or equal to

This operator checks which operand is greater or equal to each other and gives the result as a Boolean expression.

( A >= B ) will return False

<=

Lesser than or equal to

This operator checks which operand is less than or equal to each other and gives the result as a Boolean expression.

( A <= B ) will return True

==

Equality

This operator checks whether the operands are equal to each other or not and gives the result as a Boolean expression.

( A == B ) will return False

!=

Not equal

This operator checks whether the operands are not equal to each other or not and gives the result as a Boolean expression.

( A != B ) will return True

Consider the following code in the Dart language that explains the concept of Equality and Relational Operator

Program

void main( )

{

  int a = 25, b = 30 ;




  // Greater than Relational Operator

  var res1 = a > b ;

  print( ' \n Is a greater than b ? ' ) ;

  print ( res1 ) ;




  // Lesser than Relational Operator

  var res2 = a < b ;

  print( ' \n Is a lesser than b ? ' ) ;

  print ( res2 ) ;




  // Greater than or equal to Relational Operator

  var res3 = a >= b ;

  print( ' \n Is a greater than equal to b ? ' ) ;

  print ( res3 ) ;




  // Lesser than or equal to Relational Operator

  var res4 = a <= b ;

  print( ' \n Is a lesser than equal to b ? ' ) ;

  print ( res4 ) ;




  // Equal to Operator

  var res5 = a == b ;

  print( ' \n Is a equal to b ? ' ) ;

  print ( res5 ) ;




  // Not equal to Operator

  var res6 = a != b ;

  print( ' \n Is a not equal to b ? ' ) ;

  print ( res6 ) ;

}

Output

Is a greater than b ?

false


Is a lesser than b ?

true


Is a greater than equal to b ?

false


Is a lesser than equal to b ?

true


Is a equal to b?

false


Is a not equal to b ?

true

Related Topics

Dart Sets

Sets data type in Dart A set is an unordered collection of items that are unique. Dart infers that sets tale strings as values. Example, var languages = { ‘Dart’ , ‘Flutter’, ‘Python’,...

3 minutes read.

Dart Anonymous Function

Dart functions are the user defined functions that are designed to perform specific task. The use case of the functions is that they can be directly called any number of...

3 minutes read.

Dart Installation Guide

There are various ways of compiling and running an application created in Dart, either by compiling the Dart code to JavaScript using the Dart2js tool or by running on the...

3 minutes read.

Dart Basic Program

Dart provides various convenient platforms to code and compile the program in Dart language. Some of them are: 1. Using IDE = Visual Studio code is a text editor with IDE....

3 minutes read.

C++ vs Dart

Difference between C++ and Dart C++ is an object-oriented programming language developed in 1980 by Bjarne Stroustrup. It has wide real-world applications with various in-built functions and a very vast library...

1 minute read.

Dart Break and Continue

Loop statements are used to change the normal sequence of flow of the program. Dart supports two types of loop control statements: Break StatementContinue Statement Break Statement : The ‘ break ’ statement is...

4 minutes read.

Dart Arithmetic Operators

Arithmetic Operators comprises of all the operators that are used to perform arithmetic operations such as addition, subtraction, multiplication, division, etc. They are binary operators that work upon two operands. Consider A...

2 minutes read.

Dart Static Members

Static Members in Dart Static members are the members of the class declared using the 'static' keyword. the static members have the following characteristics :  All the objects of the class having...

3 minutes read.

Dart Syntax

In the previous tutorial, we coded our first program in Dart on various platforms understanding the basic functionality of each line of code.  Let us understand the syntax for Dart language...

4 minutes read.

Dart Types of Functions

Functions are the set of statements intended to perform a specific task. They accept some input from the user, perform the specified computation and generate the output. They are very...

4 minutes read.

Unit Testing in Dart

Typing testing ensures that your app keeps working as you add more features or change existing functionality. Unit testing helps to confirm the behavior of a single function, method, or...

4 minutes read.

Dart Generators

Synchronous Generator Dart Generator is a unique function that allows us to generate price sequences. Generators return values when needed; means that the value is generated if we try to duplicate...

5 minutes read.

Dart Objects

Apart from the built-in data types, Dart offers some other data types that have a special role to play. One of them is Objects.  Objects Objects are the foundation of the...

3 minutes read.

Dart Operators Precedence and Associativity

Precedence of operators determines the order in which the operators are evaluated if they are grouped together in a sentence. If two operators share an operand then the one with...

5 minutes read.

Dart Numbers

Dart provides an in-built data type ‘Numbers’ that provides two types of values: intdouble 1. int data type int data type supports integer values, and their size or values range is platform-dependent. Integers...

4 minutes read.

Dart Switch Case Statement

In the case of if-else statements, we prefer not to use the if-else ladder when there are many test conditions to be evaluated. In such a situation, it is preferable...

4 minutes read.

Dart Built-in Data Types

A data type defines the type of value a variable can hold, such as integer, double, or string.  Dart supports two data types:  1. Built-in data types : These are the data...

1 minute read.

Dart Booleans

Booleans Dart has a data type named ‘bool’ to represent Boolean values : true and false, which are compile-time constants. ‘True’ or ‘False’ cannot be assigned with values 1 or 0. Example, bool...

1 minute read.

Dart Logical Operators

Logical operators are the operators that combine two or more conditions, and accordingly return a Boolean value : true or false. Assume the value of variable A is 25 and B...

2 minutes read.

Dart URIs

The Uri class supports encoding and decoding of strings with the help of functions to be used in URIs ( which may also be known as URLs ). These functions...

6 minutes read.