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 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