Skip to content
Course map | Lesson 4 of 5

Data Structures · 4.4

Enums

All lessons are open — jump whenever you need.

enum Color {
    Red,
    Green,
    Blue,
    Custom(int, int, int),
}

let c = Color.Custom(255, 128, 0)
let name = match c {
    Color.Red          => "Red",
    Color.Green        => "Green",
    Color.Blue         => "Blue",
    Color.Custom(r, g, b) => "RGB({r},{g},{b})",
}
print(name)

Goal: Create an enum Direction with North/South/East/West and a function that returns the opposite.

lesson-4-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