Learn Courses My Dashboard

Module 2: Challenge 5

I just started working on Challenge 5 for Module 2 and I feel I got most of this structure correct, but the for statement appears to be missing something. It is throwing an expected pattern error message on screen. Any advice?

let names = ["Bob", "Matt", "Jane", "Terra"]

class Person{
    
    var name = ""
    func introduceMyself(){
        print("Hi, my name is \(name)")
    }
}

class Chef: Person{
    override func introduceMyself(){
        print("Hi, my name is \(name)")
        print("I'm a Chef")
    }
}

class Poet: Person{
    override func introduceMyself(){
        print("Hi, my name is \(name)")
        print("I'm a Poet")
    }
}

class Astronaut: Person{
    override func introduceMyself(){
        print("Hi, my name is \(name)")
        print("I'm an Astronaut")
    }
}

for(int i=0, i < 10, i++){
    let choice = Int.random(in: 0...2)
    let rndName = Int.random(in: 0..<names.count)
    if(choice == 0){
        let person = Chef()
        person.name = names[rndName]
        person.introduceMyself()
    }
    else if(choice == 1){
        let person = Poet()
        person.name = names[rndName]
        person.introduceMyself()
    }
    else if(choice == 2){
        let person = Astronaut()
        person.name = names[rndName]
        person.introduceMyself()
    }
}

Search the swift language guide, the syntax you’re using to write a for loop is wrong

I rechecked the lesson on loops and realized I was using the C++ syntax for for loops. I change it to a for in loop and now it works.

let names = ["Bob", "Matt", "Jane", "Terra"]

class Person{
    
    var name = ""
    func introduceMyself(){
        print("Hi, my name is \(name)")
    }
}

class Chef: Person{
    override func introduceMyself(){
        print("Hi, my name is \(name)")
        print("I'm a Chef")
    }
}

class Poet: Person{
    override func introduceMyself(){
        print("Hi, my name is \(name)")
        print("I'm a Poet")
    }
}

class Astronaut: Person{
    override func introduceMyself(){
        print("Hi, my name is \(name)")
        print("I'm an Astronaut")
    }
}

for _ in 0..<10{
    let choice = Int.random(in: 0...2)
    let rndName = Int.random(in: 0..<names.count)
    if(choice == 0){
        let person = Chef()
        person.name = names[rndName]
        person.introduceMyself()
    }
    else if(choice == 1){
        let person = Poet()
        person.name = names[rndName]
        person.introduceMyself()
    }
    else if(choice == 2){
        let person = Astronaut()
        person.name = names[rndName]
        person.introduceMyself()
    }
}