Conditions

Last updated 3 months ago

if statement

The if statement executes statements based on some conditions.

Example

with console from std:io
if(a < 10)
console->out:"a is smaller than 10"
else if(a is 11)
console->out:"a is 11"
else if(a > 11 and a < 21)
console->out:"a is greater than 11 and smaller than 21"
else
console->out:"a is " + a
end

An if block can contain multiple else if block.

Example

with console from std:io
if(condition)
console->out:"yes"
else if(otherCondition)
console->out:"maybe"
else if(otherOtherCondition)
console->out:"maybe not"
else
console->out:"no"
end

match block

The match block is similar to a switch block in C languages. Match cases accept lambdas as actions. If multiple match cases evaluate to true, the first match case is invoked, except if specified otherwise (with to multiple).

Example

with console from std:io
let fruit = "Apple"
var lambda action = { _ =>
console->print("Variable is of type string")
}
match(fruit) to
"Apple" => { _ => console->out:"Apples are really tasty!"}
fruit->type() is "string" => action
end
//Output: Apples are really tasty!
match(fruit) to multiple
"Apple" => { _ => console->out:"Apples are really tasty!"}
fruit->type() is "string" => action
end
/*
Output:
Apples are really tasty!
Variable is of type string
*/