12 Days of Baddass Courses sale! Get instant access to the entire egghead library of courses and lessons for 58% off.

Runs out in:
15 : 05 : 51 : 26
Become a member
to unlock all features

    Imperative Loops (for & while) in Reason

    Nik GrafNik Graf

    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.



    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson




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

    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.

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