For Loop Help

This is a discussion on For Loop Help within the C++ Programming forums, part of the General Programming Boards category; *EDIT* Ok i figured it out, sq.h was getting set to 0 after the second loop went threw one time, ...

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    1

    For Loop Help

    *EDIT* Ok i figured it out, sq.h was getting set to 0 after the second loop went threw one time, I do not understand Y so if anyone wants to fill me in on that then go ahead. i dont see anywhere in the code where i set sq.h to 0.

    I swear ive done this before...

    Code:
    void GSystem::DrawBoard()
    {
    	SDL_Rect sq;
    	sq.x= 0;
    	sq.y= 0;
    	sq.w= 80;
    	sq.h= 60;
    	Uint32 col= 0xFFFFFFFF;
    
    	for(int j= 0; j < 641; j+= sq.w)
    	{
    		sq.x= j;
    		for(int i= 0; i< 481; i+= sq.h)
    		{
    			sq.y= i;
    			SDL_FillRect(mVideoSurface, &sq, col);
    			if(i==480)
    				break;
    		}
    		if(j==640)
    			break;
    	}
    }
    It enters the first loop, then enters the socond. the first way i had it i would hit 480 and stop incrementing, this way though it makes it through, hits the IF and exits the second loop, and then continues the first loop back into the socond loop, thats when i stops incrementing. it just stays at 0 the second time threw. Any suggestions or questions?
    Last edited by _-SicK-_; 04-19-2009 at 12:28 PM.

  2. #2
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,293
    Remove the if statements and change the numbers in the for loops back to 640 and 480.

    "through" is the word you were looking for back there, not "threw".
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21