TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

SOLVED: Question about day 5

Forums > 100 Days of Swift

Hello guys,

I had a small question about day 5 question:

Accepting parameters Question 1/12: This code is valid Swift – true or false?

func count(to: Int) { for i in 1...to { print("I'm counting: (i)") } }

I clicked wrong but it was valid code. I am confused, ok I know its missing callback func but it fine* but also in the code it says 1...to and I tried to run it in playground. (Didnt run)

Am I missing anything? Just checking for clarification.

Thx.

3      

There is a small error, but I'm not sure if it is on the actual question or just the way that you wrote it here. The error is that it is missing a \ in the print line. I have fixed it below. With that change, you can run a program like this.

func count(to: Int) {
    for i in 1...to {
        print("I'm counting: \(i)")
    }
}

count(to: 5)

(You could still run the program without making the change, but it would just print "(i)" on every line instead of the actual value.)

The function definition itself is still valid swift code, even if it never gets called. But running the program won't do anything unless you actually make a call to the function.

4      

Hacking with Swift is sponsored by String Catalog.

SPONSORED Get accurate app localizations in minutes using AI. Choose your languages & receive translations for 40+ markets!

Localize My App

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.