Skip to content
5 of 15

Making decisions ​

if and else choose between branches, and while repeats while a condition holds:

pleno
let temperature = 23;
if (temperature > 25) {
    print("hot");
} else if (temperature > 15) {
    print("pleasant");
} else {
    print("cold");
}
Run

match compares a value against several patterns, and _ matches anything:

pleno
let day = "Sat";
let kind = match (day) {
    case "Sat", "Sun" => "weekend",
    case _ => "weekday"
};
Run

Your turn ​

Print FizzBuzz for 1 to 15: Fizz for multiples of 3, Buzz for multiples of 5, FizzBuzz for both, and the number otherwise.

control-flow.pln
for (n in 1..=15) {    // Print Fizz, Buzz, FizzBuzz or n.    print(n);}