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 trialRonald James
Courses Plus Student 463 Pointswhats the problem
whats wrong with my while loop ?
let numbers = [2,8,1,16,4,3,9]
var sum = 0
var counter = 0
// Enter your code below
while numbers {
continue(counter)
counter += 6
}
1 Answer
Alex Koumparos
Python Development Techdegree Student 36,887 PointsHi Ronald,
In Swift, the condition for a while loop must be a Bool (or an expression that evaluates to a Bool). Your condition numbers
is an array. Typically you want to compare something to something else (and that comparison will evaluate to a Bool). For example:
while a < b {
print("I'm in a loop")
The challenge instructions gives you a hint that you might want to compare the count property on numbers to something.
Once inside the loop, you need to modify a variable so that once the loop has run the correct number of times, it will terminate.
In your loop you are increasing counter
by 6. However, your while
conditional never compares anything to counter
so changing the value of counter
doesn't do anything. Even if it did, I don't think you'd want to increase it by 6 every time you go through the loop.
Hope these hints point you in the right direction. Let me know if you are still stuck after trying the changes I've described.
Cheers
Alex