Skip to content
Course map | Lesson 4 of 5

Null Safety · 5.4

guard

All lessons are open — jump whenever you need.

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

Global index

Find your way through Zolo

Try an idea

Start here

9 results

9 results

enespt-br