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 trialAllison Reitz
2,992 PointsFor Loop Continues Forever?
My code is exactly the same as the video, but the loop doesn't seem to stop when i becomes greater than 3.
I get a continuous stream of large numbers in my output, and finally an (lldb) at the end.
Here's my code:
#include <stdio.h>
int main()
{
int many[] = {2, 4, 8};
int sum = 0;
for (int i=0; 1 < 3; i++) {
sum += many[i];
printf("i %d sum %d\n", i, sum);
}
return 0;
}
and here's the end of my output:
... i 135700 sum -492767949 i 135701 sum -492767949 i 135702 sum -492767949 i 135703 sum -492767949 i 135704 sum -492767949 (lldb)
1 Answer
Caleb Kleveter
Treehouse Moderator 37,862 PointsHi Allison, I edited your code with markdown so it is easier to read. I think your problem is you wrote '1 < 3', instead of 'i < 3'. Hope that fixes it!
Allison Reitz
2,992 PointsAllison Reitz
2,992 PointsAha! Haha, thanks so much!
Caleb Kleveter
Treehouse Moderator 37,862 PointsCaleb Kleveter
Treehouse Moderator 37,862 PointsGlad to help!