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 trialJosh Warden
616 PointsGiven an array of numbers, print out each number in the array using a while loop and the println statement.?????
I can't figure out how to do this?
let numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
4 Answers
Nisarg Rajvi
Courses Plus Student 733 Pointshey josh!
the answer Jari gave is 50% correct answer because if you will try that code you won't get output what they have asked!
here is the correct one :
let numbers : [Int] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
var i = 0
while i < numbers.count {
println("\(numbers[i])")
i++
}
Jari Koopman
Python Web Development Techdegree Graduate 29,349 Pointsthe code could be something like:
let numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
var index = 0
while index < numbers.count {
println(numbers[index])
index++
}
I hope you can go on with your course! I don't exactly know how far you are in your course so this answer can be a bit confusing. I hope it's not!
Jacob Dobson
5,122 PointsJari, yours looks good, except we were taught to do it, speaking on the 5th line, with just "i++" in your case. Our examples just used the word index, which I assume is what i stands for. So with "index" in the variable you type "index++" on line 5. And always after the print statement!
Malerie Anderson
4,941 PointsHi Josh!
It would be helpful to know which part you're stuck on specifically. It's hard to know what question to answer when you just say that you don't know how to do it. I'd recommend re-watching the videos if you aren't sure where to start and including your code in the question so we can help you figure out what's not working for you. :)
Josh Warden
616 PointsThank you for your help
Josh Warden
616 PointsThank You all
Alexander Davison
65,469 PointsAlexander Davison
65,469 PointsThis means the challenge wants you to iterate through the elements (items) of the array, and print them. Iterating an array means to go through every element of an array and doing something. In this case, printing.