Thread: Thats not right...

  1. #1
    Registered User CAP's Avatar
    Join Date
    May 2002
    Posts
    179

    Thats not right...

    Uh, this code is from the Sam's Teach Yourself C Programming in 21 days and it never stops, what exactly is wrong with it?

    Code:
    #include <stdio.h>
    
    int count;
    
    int main(void)
    {
    	
    	
    	for(count=1; 1<=20; count++)
    		
                    printf("%d\n",count);
    
    	return 0;
    }
    I have no idea why it won't stop and I know this is simple I was just trying to refresh the stuff about loops but this is confusing...
    -Microsofts Visual C++ Introductory Kit-
    Current Projects: Learning Everything C.

    Everyone has a photographic memory, some people just don't have any film.
    ______________________________

    When was the last time you went for a colon cleansing? Because quite frankly, you're so backed up with crap that it's spilling out your mouth

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>for(count=1; 1<=20; count++)

    Look at the middle section of the for loop. That controls when the loop will terminate. What do you make of it?
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Climber spoon_'s Avatar
    Join Date
    Jun 2002
    Location
    ATL
    Posts
    182
    in the for loop, it is checking if the number one (1) is less than or equal to 20. This will always be true.

    It should be checking count.


    spoon_

  4. #4
    Registered User CAP's Avatar
    Join Date
    May 2002
    Posts
    179
    *Sits quitely, pulls out gun, BLAM!*

    But thanks anyways.
    -Microsofts Visual C++ Introductory Kit-
    Current Projects: Learning Everything C.

    Everyone has a photographic memory, some people just don't have any film.
    ______________________________

    When was the last time you went for a colon cleansing? Because quite frankly, you're so backed up with crap that it's spilling out your mouth

Popular pages Recent additions subscribe to a feed