Public Group

while / if... why wont this work

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

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 &gt;= i){ // does not work
if (COLUM_AMOUNT &gt;= i){// works
for(int s = 0;ROW_AMOUNT &gt; 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 &lt;= s){
i++;
s = 0;
if(COLUM_AMOUNT &lt;= i){
i = 0;}
}
}}



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 on other sites
I dont get any errors (when using "while"), just the game locks up right from the beginning (with "if" all is good).

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 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" :)

1. 1
2. 2
3. 3
Rutin
16
4. 4
JoeJ
13
5. 5

• 10
• 9
• 14
• 10
• 25
• Forum Statistics

• Total Topics
632646
• Total Posts
3007637
• Who's Online (See full list)

There are no registered users currently online

×