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

Stephane Bourdon
Stephane Bourdon
546 Points

Hello, challenge task on for loop, I cannot get it right?

I don't understand the "no longer passing"

variable_assignment.mm
int mathTotal;
bool isComplete;

for (mathTotal = 5; mathTotal <=24; mathTotal ++)
{
  if (mathTotal==25)
     {
     isComplete = TRUE;
     }
}

1 Answer

Jaroslaw Adamowicz
Jaroslaw Adamowicz
11,634 Points

Hi, from the code I suspect it will never get to if statement.

When your loop reach 24 it ends, it will never reach 25. Please try to change value in if to 24 or value in for loop check to 25.

So either that:

int mathTotal; bool isComplete;

for (mathTotal = 5; mathTotal <=25; mathTotal ++)
{
  if (mathTotal==25)
     {
     isComplete = TRUE;
     }
}

or that:

int mathTotal;
bool isComplete;

for (mathTotal = 5; mathTotal <=24; mathTotal ++)
{
  if (mathTotal==24)
     {
     isComplete = TRUE;
     }
}

will do!

Cheers!