Introduction

In this section, we'll dive into the functionality of conditional expressions.

What Are Conditional Expressions?

Conditional expressions, or simply conditionals, are a subgroup of expressions that only execute code when a certain condition is fulfilled.

Conditional expressions are a very powerful feature in any programming languages as they tell the compiler to make different decisions based on the current state of a part of the program. This allows applications to become smarter and more flexible.

Reason’s Approach

Conditionals in Reason follow a simple convention to reach an outcome:

In case <expression1> is true
Execute <expression2>
Otherwise, execute <expression3>

The logic behind conditionals allows us to form complex conditional expressions.

ReasonML has three different types of conditionals:

  • if - else
  • switch
  • ternary operator

Each has its own flavor of convenience. At the end of this section, we’ll be familiar with the unique features of each conditional.


In the next lesson, we’ll dive into the if-else expression.

Get hands-on with 1200+ tech skills courses.