Save 45% for a limited time.

Get access to all courses and lessons on egghead today.


    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: 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.