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

mustafa attaie
mustafa attaie
8,068 Points

i think i wrote my code fine at this challenge?

I'm not sure what is wrong with my code. Can someone please explain to me what i did wrong?

variable_assignment.mm
int mathTotal;
  bool isComplete;

for(int i = 5; i = 25; i++;) {
  mathTotal = mathTotal + i;
  bool isComplete = true;
}

3 Answers

LaToya Legemah
LaToya Legemah
12,600 Points

Almost! Unfortunately there are a few things wrong. You don't need the semicolon after the i iteration and I took out the i = 25, i put " i is less then 26 ". That way it should loop until it hits 25 then stop. Lastly the isComplete Boolean is already declared. So you can simply use it's name. I put the isComplete outside the loop so when it hits 25 it becomes true. If you keep it in the loop it becomes true each iteration.

Your code should be as follows:

int mathTotal;
bool isComplete;

for(int i = 5; i < 26; i++) {
 mathTotal = mathTotal + i;
}
 isComplete = true;
mustafa attaie
mustafa attaie
8,068 Points

i seem to still be having problems. It tells me did you use a correct conditional stop? i believe we did?

mustafa attaie
mustafa attaie
8,068 Points

oh nvm i found the problem

mustafa attaie
mustafa attaie
8,068 Points

oh nvm i found the problem