Erlang - Relational Operators



Following are the relational operators available in Erlang.

Operator Description Example
== Tests the equality between two objects 2 = 2 will give true
/= Tests the difference between two objects 3 /= 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
erlang_operators.htm
Advertisements