A Tour of Morfa

For loop

Unlike in many imperative languages, Morfa for loop does not use a control variable which is tested and explicitely incremented in each iteration. Instead, for iterates over an "iterable" value such as an array or a range.

import basics.control_flow.if_then_else: fizzbuzz;
import morfa.util.Range;

unittest
{
    // Iterate over an array of numbers from 0 to 9
    for (n in [0,1,2,3,4,5,6,7,8,9])
    {
        fizzbuzz(n);
    }

    // Iterate over numbers from 10 to 100
    for (n in range(10,101))
        fizzbuzz(n);
}

Note that the upper limit of range is exclusive: in order to include the value of 100 you have to use range(10, 101).

As a syntactic sugar you may write k .. n instead of range(k,n):

unittest
{
    for (n in 0..101)
        fizzbuzz(n);
}