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

Need Help with for Loop assignment

i can't seem to get the for loop right. can anyone give me a hand?

variable_assignment.mm
int mathTotal;
bool isComplete;

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

  mathTotal = 25, isComplete = true;
}

2 Answers

isComplete = mathTotal >= 25 ? true:false;

That is what I used -- I don't think you need the parenthesis and it may reject the answer because it asks to assign true to isComplete and not Yes.

and don't forget the semicolon

Hey Travis,

Thank you for your help!! it worked!

Hey Deniz,

It took me a minute to get this one too! It takes a ternary operator because you are evaluating the condition of isComplete as true or false. Your 3 operands being isComplete, the true result, and false result. The full explanation is in Video 3 under More Operators beginning at 2:52.

Hey Travis,

i went back and watched the video adding

isComplete = (mathTotal = 25) ? YES:NO

but i can't seem to get the answer right.