Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

I am having to write a for-in loop with a switch statement inside for countup in 1...50{

for-in loop

for countup in 1...50{ switch isEven { case let 1...50 where isEven %2 ==0

Is this a part of a challenge? If so can you link it?

create a loop to iterate through the integers 1 through 50. use a switch statement to display a message that includes the number and whether the number is even, divisible by 3, or divisible by 5. If none of these apply, display "non apply". Show results in console

An amazing person and genius, Brian Mahoney

1 Answer

My MacBook is down but I got it to work on iSwift.org with the code below.

for number in 1...50 {
    switch number {
        case number where number % 2 == 0:
            print("\(number) is even")
        case number where number % 3 == 0:
            print("\(number) is divisible by 3")
        case number where number % 5 == 0:
            print("\(number) is divisible by 5")
        default: "None apply"
    }
}

I want to cry, thank you so much!!!! I appreciate you immensenly, you are a genius. I wont forget who helped me, I promise.

Sweet, then you should totally mark this as the best answer ;)

Loops best answer...Amazing person and genius Brian Mahoney