Imperative Loops (for & while) in Reason

Nik Graf
InstructorNik Graf

Share this video with your friends

Send Tweet
Published 4 years ago
Updated 3 years ago

In functional programming languages map, filter and reduce are often preferred over imperative loops. As stated in the official Reason docs the language creates don't have a preference on whether you should use a loop over these function.

In Reason we have for as well as while available.

Instructor: [00:00] We can use for loops to iterate from the starting value up to the ending value. The ending value is included.

[00:14] Keep in mind, though, it must be a valid range going from a lower to a higher integer. Otherwise, it won't go through any of these items. In order to make the loop count in the opposite direction, we can replace to with down-to.

[00:32] In addition, we have while loops at our disposal. They loop as long as the test condition inside the parentheses is true.

[00:39] [silence]