It's time to address the elephant in the room, if statements. If statements are ways to check conditions and run code in different manners.
For example, we can just use a single if keyword followed by an expression to run code.
obj x = 5;
if x == 5 { # glang supports the '==', '!=', '>=', '<=', 'and', 'or', 'not' operators
bark("x is 5!");
}
We can go a step further and use the otherwise keyword to add what's called a "default case". This is what case is triggered if no conditions match; think of it like a backup generator for a building, it only runs if all power fails.
obj x = 10;
if x == 5 {
bark("x is 5!");
} otherwise {
bark("something happened:( x is not 5");
}
The alsoif keyword is used in chain with if statements to essentially check expressions if other expressions fail. It's a step above the otherwise case; like the fuse panel for a building.
obj x = 10;
if x == 5 {
bark("x is 5!");
} alsoif x == 10 {
bark("x is 10!");
} otherwise {
bark("something happened:( x is not 5");
}
There can be as many alsoif cases as needed:
obj x = 10;
if x == 1 {
bark("x is 1!");
} alsoif x == 2 {
bark("x is 2!");
}
# ...
alsoif x == 9 {
bark("x is 9!");
} alsoif x == 10 {
bark("x is 10!");
} otherwise {
bark("something happened:( x is not 5");
}