Skip to content
← Index | Lesson 2 of 5

if let

if let for safe unwrap

if let safely unwraps an optional:

let value: int? = 42

if let v = value {
    print("Value: {v}") // only runs if not nil
} else {
    print("Was nil")
}

Goal: Use if let to print the length of an optional name, or "Name not provided" if nil.

lesson-5-2.zolo
Program output

Run the code to see the output

Search Zolo

9 results

enespt-br