If...Else: if as a value
● Beginner2 min
An if is a value: it picks between two values in one line.
fn main() {
const paid = false
const label = if paid { "paid" } else { "due" }
print(label)
}The program ran and printed:
kavach run value.kav
dueEach block's last line is its value. This replaces the ? : operator of other languages, with words a beginner can read. Both branches must give the same type.