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");
}Runmatch compares a value against several patterns, and _ matches anything:
pleno
let day = "Sat";
let kind = match (day) {
case "Sat", "Sun" => "weekend",
case _ => "weekday"
};RunYour turn
Print FizzBuzz for 1 to 15: Fizz for multiples of 3, Buzz for multiples of 5, FizzBuzz for both, and the number otherwise.