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

C for loop quiz: Am I missing something?

Ok, the quiz asks: Let's create a for loop which will loop 5 times and print the value of "i". Fill in the blanks below.

So I submit the following code.

for (int i = 0; i < 5; i++) { printf("%d\n", i); }

The quiz answer says this is incorrect. However when I run it in Xcode, sure enough the thing loops five times and spits out the value of i.

I know this is totally a noob question, but what am I missing here? Why is the quiz telling me I'm wrong?

2 Answers

Not sure if it is relevant, but I have had issues with declaring variables inside for loops in C before.

Maybe try

int i;
for (i = 0; i < 5; i++) {
  printf("%d\n", i);
}

Good. Just so I'm not crazy and this is on Treehouse, not me.