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 Objective-C Basics Scope and Loops Review Scope and Loops

loop syntax error?

int mathTotal; bool isComplete;

for (int i = 5; i < 25; i++){ mathTotal += i; }

isComplete = YES;

it keeps telling me better check for syntax error, but it looks right to me... what did i do wrong? thanks.

variable_assignment.mm
int mathTotal;
bool isComplete;

for (int i = 5; i < 25; i++){
  mathTotal += i;
}

isComplete = YES;

1 Answer

Hi there,

You need to reach 25 so use less than or equal to:

int mathTotal;
bool isComplete;

for (int i = 5; i <= 25; i++){
  mathTotal += i;
}

isComplete = true;

And I don't know if YES is OK, or if you need to use true. The above code worked.

I hope that helps,

Steve.

I tried it in the quiz but didn't work i guess i'll try again, thanks Steve!

Just checked; YES works fine is it is just the bounds test of i that's wrong. If you just use less than, i will never reach 25 which is what the challenge asks for. So the loop terminator needs to be less than or equal to 25 so that the value 25 is included in the end result of mathTotal.

Steve.

Hi Steve, yes that's right it worked! thanks so much!! I was trying to do more lessons on object oriented programming but the site said the page doesn't exist...

Glad you got that working.

Let me know if the page still doesn't load. That seems odd.

Steve.

I asked treehouse, they said they will release the new lessons sometime next week :)