Extended Switch
- It’s possible to have an extended
switch
, which can take any type of conditionals.
xxxxxxxxxx
import std::io;
fn bool is_odd(int x)
{
return x % 2 == 0;
}
fn void main()
{
int x = 2;
switch
{
case x == 1:
io::printfn("One");
case is_odd(x):
io::printfn("Odd");
case x < 0:
io::printfn("Negative");
case x == 0:
io::printfn("Zero");
default:
io::printfn("Number was: %d", x);
}
}