Thread: 2 for loops...dunno why its skipping loop 2

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    9

    2 for loops...dunno why its skipping loop 2

    Ok..this is just 2 for loops and I cant figure out why its not even making it into the 2nd loop. I goes from 5 to 0 at --, right? No semicolons in the wrong spot...what the heck?!

    Code:
    for(j=0; j<total/6; j++) {  /* loop 1 */
    		//radix_total=0;
    		for(i=5; i=0; i--) { /* loop 2 */
    			printf("test line");
    			/* its not evening making it into this 2nd loop */
    			fscanf(inputfile, "%d", next_char);
    			printf("next_char has %d\n", next_char); 
    			if (next_char == 1)
    				radix_total = radix_total + (int)pow(2, i);
    
    			}
    		
    		/* stuff after exiting loop 2 which is working fine */
    any advice appreciated. The radix total line just happened to be commented out when I copied it here. Makes no difference either way.

  2. #2
    .........
    Join Date
    Nov 2002
    Posts
    303
    Your for loop initializes i to 5, and then goes into a loop only if i is 0. This is never true, because you initialized i to 5 and well 5 is not equal to 0. To fix it do something like i != 0 instead.

  3. #3
    Registered User
    Join Date
    Dec 2002
    Posts
    9
    Ugh...man...I tried i=5; i<-1 and <=0 but that didnt seem to work. Maybe i'm just tired. i != 0 definately helps though so many thanks.

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    for(i=5; i>0; i--)

    or

    for(i=5; i>=0; i--)
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Visual Studio Express / Windows SDK?
    By cyberfish in forum C++ Programming
    Replies: 23
    Last Post: 01-22-2009, 02:13 AM
  2. Personal Program that is making me go wtf?
    By Submeg in forum C Programming
    Replies: 20
    Last Post: 06-27-2006, 12:13 AM
  3. A somewhat bizzare problem!!! - WHILE LOOP
    By bobthebullet990 in forum C Programming
    Replies: 3
    Last Post: 03-31-2006, 07:19 AM
  4. loop issues
    By kristy in forum C Programming
    Replies: 3
    Last Post: 03-05-2005, 09:14 AM
  5. when a while loop will stop ?
    By blue_gene in forum C Programming
    Replies: 13
    Last Post: 04-20-2004, 03:45 PM