If expressions

An if condition is always bool. For effects, else is optional. When the expression supplies a value, every branch must exist and produce the same type.

Because blocks have values, you do not need a separate conditional operator. Put the chosen if directly on the right side of a binding.

fn main() {
  let count = 12
  let size = if count > 10 { "large" } else { "small" }
  println(size)
}
Output & diagnostics
Expected:
large
Ctrl/⌘+Enter runs the current lesson.