Skip to content
← Index | Lesson 4 of 5

guard

guard for early return

guard checks a condition and exits the function if it fails:

fn process(name: str?) -> str {
    guard name != nil else {
        return "Name required"
    }
    let present_name = name ?? ""
    return "Hello, {present_name}!"
}

Goal: Implement validate_age that returns "Adult" or "Minor" using guard.

lesson-5-4.zolo
Program output

Run the code to see the output

Search Zolo

9 results

enespt-br