Skip to content
Course map | Lesson 2 of 5

Null Safety · 5.2

if let

All lessons are open — jump whenever you need.

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

Global index

Find your way through Zolo

Try an idea

Start here

9 results

9 results

enespt-br