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!

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 (Retired) Functional Programming in C Control Flow - For Loops

Allison Reitz
Allison Reitz
2,992 Points

For 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
Caleb Kleveter
Treehouse Moderator 37,862 Points

Hi 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!