UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

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.



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.


BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

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.