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 Swift Basics (retired) Control Flow If Statement

Justin Luce
Justin Luce
439 Points

I cannot figure out this problem, can someone please help me?

I have tried multiple times :(

1 Answer

They want you to use the for-in loop. You can use any variable name you want. Here I used i. Then they want you to test each i to see if it is a 1, 2 or 3. I did this in an if... else if... but you could probably have used a switch statement instead, although I didn't test that. The surprising thing is that the challenge required the use of println(), rather than print(), as println() which is no longer part of Swift 2.0. But maybe this course is still Swift 1.0.

let months = [1, 2, 3]
for i in months {
  if i == 1 {
    println("January")
  } else if i == 2 {
    println("February")
  } else if i == 3 {
    println("March")
  }
}
Caleb Kleveter
Caleb Kleveter
Treehouse Moderator 37,862 Points

This course is for Swift 1.2. If the course is for Swift 2.0, then it will say in the course name, else it is 1.2.