Erlang – Relational Operators

Erlang Relational Operators

Following are the relational operators available in Erlang.

OperatorDescriptionExample
==Tests the equality between two objects2 = 2 will give true
/=Tests the difference between two objects3 /= 2 will give true
<Checks to see if the left object is less than the right operand.2 < 3 will give true
=<Checks to see if the left object is less than or equal to the right operand.2 =<3 will give true
>Checks to see if the left object is greater than the right operand.3 > 2 will give true
>=Checks to see if the left object is greater than or equal to the right operand.3 >= 2 will give true

The following code snippet shows how the various operators can be used.

Example

-module(helloworld). 
-export([start/0]). 

start() -> 
   io:fwrite("~w~n",[3==2]), 
   io:fwrite("~w~n",[3/=2]), 
   io:fwrite("~w~n",[3<2]), 
   io:fwrite("~w~n",[3=<2]), 
   io:fwrite("~w~n",[3>2]), 
   io:fwrite("~w~n",[3>=2]).

The output of the above program will be −

Output

false
true
false
false
true
true

Next Topic : Click Here

This Post Has 2 Comments

Leave a Reply