Introduction
This section will teach us about the mechanics of iteration in ReasonML.
We'll cover the following
What is a Loop?
A loop is categorized as a control structure that is used to execute a set of operations repeatedly for a specific number of iterations.
Like conditionals, loops play a role in controlling the flow of the program.
A big benefit of using loops is that it saves time. If a piece of code needs to run 300 times, we wouldn’t need to write it for all those instances. A loop does it for us.
Loops are most commonly used to traverse an array or list which is discussed in the next section. In principle, moving through an array element by element is an iterative process, i.e., we must traverse the list step by step repeatedly. Hence, a loop fits such a process perfectly.
Reason’s Approach
Reason supports two popular loop structures:
for
loopwhile
loop
We’ll discuss their unique behavior and features in the coming lessons.
Let’s get started with the for
loop.
Get hands-on with 1400+ tech skills courses.