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

Mia Pivirotto
Mia Pivirotto
5,557 Points

For loop question help in code challenge

The challenge is "Create a for loop that will begin with a value of 5 and end with a value of 25. In each iteration, add the incrementing value to mathTotal. When the loop has finished running, set 'isComplete' to true. (HINT: the last value used INSIDE the loop should be 25)"

And I can't figure out exactly what it's asking and how to set isComplete to true after the loop is finished.

variable_assignment.mm
int mathTotal;
bool isComplete;

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

isComplete = true;

1 Answer

Kyle Melton
Kyle Melton
6,664 Points

Inside your function you are not adding mathTotal to 'i'. You are assigning the value of i to mathTotal.

Mia Pivirotto
Mia Pivirotto
5,557 Points

I changed it to this:

int mathTotal; bool isComplete;

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

isComplete = true;

but it's still not working, and I can't figure out if I'm doing the right thing in just writing in isComplete = true; to set it to true after it runs

Kyle Melton
Kyle Melton
6,664 Points

You might try instantiating the two variables before the for loop. That might be it.