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

Michael Murray
Michael Murray
6,037 Points

Please Help - Not getting compiler errors. Code runs fine in my xcode playground.

Trying to satisfy the code challenge: Working with While ... While Loops. Here is my code:

let numbers = [2,8,1,16,4,3,9] var sum: Int = 0 var counter: Int = 0 while counter < numbers.count { sum = sum + numbers[counter] counter++ } print (sum)

Michael Murray
Michael Murray
6,037 Points

Sorry, My paste did not fully get transferred. I will try again.

4 Answers

Michael Murray
Michael Murray
6,037 Points

Got the challenge to accept my code! Apparently, as with the problem here, I must have had some keystrokes invisible to the eye in my cut-n-paste. I manually typed my code into the challenge and it was happy.

Michael Murray
Michael Murray
6,037 Points

Another attemp at pasting my code:

let numbers = [2,8,1,16,4,3,9]

var sum: Int = 0

var counter: Int = 0

while counter < numbers.count {

sum = sum + numbers[counter]

counter++

}

print (sum)

Michael Murray
Michael Murray
6,037 Points

OK . . . third attempt to put my code in. Paste leaving lines out. Suppose I must enter each line manually:

let numbers = [2,8,1,16,4,3,9] var sum: Int = 0 var counter: Int =0 while counter < numbers.count { sum = sum + numbers[counter] counter++ } print(sum)

Michael Murray
Michael Murray
6,037 Points

For some reason the conditional did not show up again in the while statement. This editor does not appear to like the "less than symbol" so I will not actually use it, instead I will put the symbols in quotes.

I have the following: while counter "less than symbol" numbers.count then the "left curly bracket" sum = sum + numbers[counter] counter++ "right curly bracket" print(sum)