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

Janson Roberts
Janson Roberts
5,071 Points

Creating A For Loop

When I try to input the for loop, I keep getting a compiler error message:

expected expression for (int i=5, i<=25, i++)

I'm not sure what to do next?

variable_assignment.mm
bool isComplete;
int mathTotal = 0;

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

2 Answers

Michael Afanasiev
PLUS
Michael Afanasiev
Courses Plus Student 15,596 Points

Hi Janson,

The loop is correct although you have a small syntax error, a for loop should look like this:

for (int k = 1; k < 99; k++) {
       // do something
}

Hint: Notice the semicolon.

Hope this helps!