Erlang - Logical Operators


Advertisements

Following are the logical operators available in Erlang.

Operator Description Example
or This is the logical “and” operator true or true will give true
and This is the logical “or” operator True and false will give false
not This is the logical “not” operator not false will give true
xor This is the logical exclusive “xor” operator True xor false 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",[true or false]),  
   io:fwrite("~w~n",[true and false]), 
   io:fwrite("~w~n",[true xor false]), 
   io:fwrite("~w~n",[not false]).

The output of the above program will be −

Output

true
false
true
true
erlang_operators.htm
Advertisements