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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Samar Khanna](https://secure.gravatar.com/avatar/2858cbdc5e899b219be1f976c1c25334?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Samar Khanna
1,757 PointsWhat will be the code if i wanted to use a switch case code block?
Hi guys, I wanted to know the code for this game if I chose to use the switch command instead?
![Samar Khanna](https://secure.gravatar.com/avatar/2858cbdc5e899b219be1f976c1c25334?s=60&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Samar Khanna
1,757 Points'''var gameNumber = 1...30
for inputNumber in gameNumber { if (inputNumber % 3) == 0 && (inputNumber % 5) == 0 { println("FizzBuzz") } else if (inputNumber % 3) == 0 { println("Fizz") } else if (inputNumber % 5) == 0 { println("Buzz") } else { println(inputNumber) } } ''' This is the code i used
1 Answer
![David Moran](https://uploads.teamtreehouse.com/production/profile-photos/1350392/micro_david.jpg)
David Moran
9,617 Pointslet fizzbuzz = 1...20
for i in fizzbuzz {
switch i {
case let i where (i % 3 == 0) && (i % 5 == 0): //
println("FizzBuzz")
case let i where (i % 3 == 0):
println("Fizz")
case let i where (i % 5 == 0):
println("Buzz")
default:
println(i)
}
}
When you want to use conditionals in a switch statement, use the where statement.
For this specific case, we're asking the variable to be used in a conditional (Use the number 3 then find out whether or not 3 % 3 == 0 is true). If the equation turns out to be true, then we will follow that case. In this case, the case will print out the line "Fizz"
![Samar Khanna](https://secure.gravatar.com/avatar/2858cbdc5e899b219be1f976c1c25334?s=60&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Samar Khanna
1,757 PointsOh k thx, i didn't know the where statement
![David Moran](https://uploads.teamtreehouse.com/production/profile-photos/1350392/micro_david.jpg)
David Moran
9,617 PointsNot a problem, always glad to help :)
![Esmobrander Ozpedelamo](https://secure.gravatar.com/avatar/9bc792ff56f22533351ae094246bd5ec?s=60&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Esmobrander Ozpedelamo
9,136 Pointsnice im new to iOS development, didn't know about the where statement, i wonder why they didn't cover that part?, kinda important i believe.
Meek D
3,457 PointsMeek D
3,457 Pointscan you post the code first for us to help you ?