Conditionals and branching are pretty easy with Hare.
use fmt;
export fn main() void = {
// Simple if else conditional
if (10%2 == 0) {
fmt::println("10 is even")!;
} else {
fmt::println("10 is odd")!;
};
// Something a bit more complex with logical operator &&
// You can even use || as well
if (10%2 == 0 && 50/2 == 25) {
fmt::println("Math is easy")!;
};
// Simple if else if conditional
if (10%2 == 1) {
fmt::println("This won't print")!;
} else if (10%2 == 0) {
fmt::println("This will print")!;
} else {
fmt::println("This also won't print")!;
};
};
$ hare run examples/if-else/if-else.ha
4/4 tasks completed (100%)
10 is even
Math is easy
This will print
Back to table of contents