Comparison Operations

From Elixir Wiki
Jump to navigation Jump to search

Comparison Operations[edit]

Comparison operations are fundamental to programming as they allow us to compare values and determine their relationship with each other. In Elixir, comparison operations are used to evaluate expressions and conditionally execute code based on the comparison results.

Equality Operators[edit]

The equality operators in Elixir are used to compare two values for equality.

== Operator[edit]

The `==` operator is used to check if two values are equal. It returns `true` if the values are equal and `false` otherwise.

=== Operator[edit]

The `===` operator is another equality operator in Elixir. It not only checks if the values are equal but also compares their data types. It returns `true` if both the values and their data types are equal, and `false` otherwise.

Comparison Operators[edit]

In addition to the equality operators, Elixir provides several comparison operators to compare values in order to determine their relationship.

> Operator[edit]

The `>` operator is used to check if the left operand is greater than the right operand. It returns `true` if the condition is satisfied and `false` otherwise.

< Operator[edit]

The `<` operator is used to check if the left operand is less than the right operand. It returns `true` if the condition is satisfied and `false` otherwise.

>= Operator[edit]

The `>=` operator is used to check if the left operand is greater than or equal to the right operand. It returns `true` if the condition is satisfied and `false` otherwise.

<= Operator[edit]

The `<=` operator is used to check if the left operand is less than or equal to the right operand. It returns `true` if the condition is satisfied and `false` otherwise.

Examples[edit]

Here are some examples that demonstrate the usage of comparison operations in Elixir:

```elixir a = 5 b = 10

IO.puts(a == b) # Outputs false IO.puts(a > b) # Outputs false IO.puts(a < b) # Outputs true IO.puts(a >= b) # Outputs false IO.puts(a <= b) # Outputs true ```

See Also[edit]