Return early
A tail expression handles the ordinary path. return value leaves the function immediately, which is useful for a small guard. A void function may use bare return.
Every path in a value-returning function must produce the declared type. moon checks that before any path runs.
fn admission(age: int) -> string {
if age < 18 { return "minor" }
"free"
}
fn main() {
println(admission(20))
println(admission(12))
}
Examples use the moon toolchain version shown beside each result.
Output & diagnostics
Expected: free minor
Ctrl/⌘+Enter runs the current lesson.