- Elixir Tutorial
- Elixir - Home
- Elixir - Overview
- Elixir - Environment
- Elixir - Basic Syntax
- Elixir - Data Types
- Elixir - Variables
- Elixir - Operators
- Elixir - Pattern Matching
- Elixir - Decision Making
- Elixir - Strings
- Elixir - Char Lists
- Elixir - Lists and Tuples
- Elixir - Keyword Lists
- Elixir - Maps
- Elixir - Modules
- Elixir - Aliases
- Elixir - Functions
- Elixir - Recursion
- Elixir - Loops
- Elixir - Enumerables
- Elixir - Streams
- Elixir - Structs
- Elixir - Protocols
- Elixir - File I/O
- Elixir - Processes
- Elixir - Sigils
- Elixir - Comprehensions
- Elixir - Typespecs
- Elixir - Behaviours
- Elixir - Errors Handling
- Elixir - Macros
- Elixir - Libraries
- Elixir Useful Resources
- Elixir - Quick Guide
- Elixir - Useful Resources
- Elixir - Discussion
Elixir - Comparision Operators
The comparison Operators in Elixir are mostly common to those provided in most other languages. The following table sums up comparison operators in Elixir. Assume variable A holds 10 and variable B holds 20, then −
Operator | Description | Example |
---|---|---|
== | Checks if value on left is equal to value on right(Type casts values if they are not the same type). | A == B will give false |
!= | Checks if value on left is not equal to value on right. | A != B will give true |
=== | Checks if type of value on left equals type of value on right, if yes then check the same for value. | A === B will give false |
!== | Same as above but checks for inequality instead of equality. | A !== B will give true |
> | Checks if the value of left operand is greater than the value of right operand; if yes, then the condition becomes true. | A > B will give false |
< | Checks if the value of left operand is less than the value of right operand; if yes, then the condition becomes true. | A < B will give true |
>= | Checks if the value of left operand is greater than or equal to the value of right operand; if yes, then the condition becomes true. | A >= B will give false |
<= | Checks if the value of left operand is less than or equal to the value of right operand; if yes, then the condition becomes true. | A <= B will give true |
Example
Try the following code to understand all arithmetic operators in Elixir.
a = 10 b = 20 IO.puts("a == b " <> to_string(a == b)) IO.puts("a != b " <> to_string(a != b)) IO.puts("a === b " <> to_string(a === b)) IO.puts("a !== b" <> to_string(a !== b)) IO.puts("a > b " <> to_string(a > b)) IO.puts("a < b " <> to_string(a < b)) IO.puts("a >= b " <> to_string(a >= b)) IO.puts("a <= b " <> to_string(a <= b))
When running above program, it produces following result −
a == b false a != b true a === b false a !== b true a > b false a < b true a >= b false a <= b true
elixir_operators.htm
Advertisements