Sign in to follow this  

while / if... why wont this work

This topic is 4200 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Why wont this work? (you only need to look at line 2 and 3) "while" wont work but if i put in "if" it works fine.
int i =0;  
             // while(COLUM_AMOUNT >= i){ // does not work   
             if (COLUM_AMOUNT >= i){// works 
             for(int s = 0;ROW_AMOUNT > s; s++){
             if(focus.screen_location.x == BLOCK_WIDTH * s && focus.screen_location.y == WINDOW_HEIGHT - (BLOCK_WIDTH * (i + 1))){
            if(CheckBlockCollision(focus) || focus.screen_location.y + BLOCK_WIDTH == WINDOW_HEIGHT){
                                          SDL_WM_SetCaption("change 1", 0);
             restingblocks[i][s] = 1;}
             }
             if(ROW_AMOUNT <= s){
             i++;
             s = 0;
             if(COLUM_AMOUNT <= i){
             i = 0;}
             }
             }}

Share this post


Link to post
Share on other sites
Define "wont work". Does it not compile? Does it not behave like you expect? Does a little gnome leap out of your CD-ROM drive and put a pancake on your head?

Share this post


Link to post
Share on other sites
A while loop will keep repeating until the condition is false. If it's always true then it loops forever and appears to have "locked up."

Share this post


Link to post
Share on other sites
The 'while' construct means exactly what it says: it keeps doing the body of the loop (the stuff within the {} associated with the while()) for as long as the condition specified holds. You specified a condition 'COLUM_AMOUNT >= i'; within the loop, neither 'COLUM_AMOUNT' nor 'i' has its value changed; so if the loop is entered, nothing can cause it to exit.

BTW, it's spelled "column" :)

Share this post


Link to post
Share on other sites

This topic is 4200 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this