Skip to content
← Index | Lesson 3 of 5

Structs

Structs in Zolo

struct Person {
    name: str,
    age: int,
}

impl Person {
    fn new(name: str, age: int) -> Person {
        return Person { name, age }
    }

    fn greet(self) -> str {
        return "Hello, I'm {self.name}!"
    }
}

let p = Person.new("Alice", 30)
print(p.greet())

Goal: Create a struct Circle with a radius field and an area method (pi ~ 3.14). Test with radius = 5, output: 78.5.

lesson-4-3.zolo
Program output

Run the code to see the output

Search Zolo

9 results

enespt-br