A Tour of Morfa

If-then-else

Syntax of the conditional statement is as in C or Java. In particular, the condition has to be put in parentheses, whereas branches consting of a single statement do not need to be wrapped in curly braces:

import morfa.io.print;

package func fizzbuzz(n: int)
{
    if (n < 0)
        return;

    if (n % 15 == 0)
    {
        println("fizzbuzz");
    }
    else if (n % 3 == 0)
    {
        println("fizz");
    }
    else if (n % 5 == 0)
    {
        println("buzz");
    }
    else
        printf("{}\n", n);
}

Morfa allows for conditional expressions as well—an equivalent of C++ ? : ternary operator:

func detectZero(i: int): text
{
    return if (i == 0) "Got it!" else "Nope...";
}

The syntax aligns with the conditional statement but being an expression, a conditional expression must have the else part, so that its value is defined also when the condition is false.