Skip to content

`if` and `match` as values

enum Shape {
Circle(f64)
Dot
}
let n = 3
let shape = Shape.Circle(2.0)
let label = if n > 0 { "positive" } else { "not positive" }
let size = match shape {
.Circle(r) => 3.0 * r * r
.Dot => 0.0
}
print(label)
print(size)
positive
12.0

They can be used where a value is stored or returned: let x = ..., x = ... and return .... A block’s value is its last line; a branch may instead leave with return, break, continue or panic. An if used as a value needs an else.