Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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)