1×
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.

Autoplay

    Imperative Loops (for & while) in Reason

    Nik GrafNik Graf
    reasonReason

    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.

    Code

    Code

    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
    Discuss

    Discuss

    Transcript

    Transcript

    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.