Jump to content
  • Advertisement
Sign in to follow this  
pascalosti

while / if... why wont this work

This topic is 4562 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[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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!