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 trialEric Witowski
Courses Plus Student 92 PointsI 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
Eric Witowski
Courses Plus Student 92 Pointscreate 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
Eric Witowski
Courses Plus Student 92 PointsAn amazing person and genius, Brian Mahoney
1 Answer
Brandon Mahoney
iOS Development with Swift Techdegree Graduate 30,149 PointsMy 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"
}
}
Eric Witowski
Courses Plus Student 92 PointsI want to cry, thank you so much!!!! I appreciate you immensenly, you are a genius. I wont forget who helped me, I promise.
Brandon Mahoney
iOS Development with Swift Techdegree Graduate 30,149 PointsSweet, then you should totally mark this as the best answer ;)
Eric Witowski
Courses Plus Student 92 PointsLoops best answer...Amazing person and genius Brian Mahoney
Brandon Mahoney
iOS Development with Swift Techdegree Graduate 30,149 PointsBrandon Mahoney
iOS Development with Swift Techdegree Graduate 30,149 PointsIs this a part of a challenge? If so can you link it?