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

Jason Teo
PLUS
Jason Teo
Courses Plus Student 8,398 Points

What's wrong with my code?

Any help?

months.swift
let months = [1, 2, 3]

for i in 1...3 {

if months[i] == 1 { 
println("January") 
} else if months[i] == 2 {
println("February") 
} else if months[i] == 3 {
println("March")
} else {
break
}
} 

1 Answer

Hi Jason,

You're mixing up the [index] number with the value contained at that index.

Have a look at my post below to see if that clears things up for you. If not, get back to me here or give me a shout on Twitter - @OnlySteveH

https://teamtreehouse.com/forum/arrays-forinifthen-assignment

Steve.