View Single Post
  #1 (permalink)  
Old 11-09-2007, 07:47 PM
Lang Lang is offline
Member
 
Join Date: Nov 2007
Posts: 8
Lang is on a distinguished road
Issues with a while loop
The code is below. What is happening is that my while statement is never evaluating to false when it should be.

I did a System.out.println(goDir) after I set it to true. It showed the value to be equal to true. Shouldn't the while loop stop as soon as the statement is false? I also tried a

Code:
do{ } while(!goDir && lastHit[i][6] > 0);
And that didn't seem to work either. Does anyone see anything wrong with this code? Also, i is always greater than 1 when this while statement goes off. So lastHit[i-1] does exist.

Code:
while (!goDir && lastHit[i][6] > 0){ System.out.println("goDir = " + goDir); System.out.println("lastHit[i][6] = " + lastHit[i][6]); if (lastHit[i][6] > 0){ System.out.println("X Difference = " + (startX - lastHit[i-1][0])); System.out.println("2 = " + lastHit[i][2]); System.out.println("3 = " + lastHit[i][3]); System.out.println("4 = " + lastHit[i][4]); System.out.println("5 = " + lastHit[i][5]); if ((startX - lastHit[i-1][0]) > 0){ System.out.println("X + 1"); if (lastHit[i][2] == 1){ if ((startX + 1) <= boardWidth){ startX++; lastHit[i][2] = 0; lastHit[i][6]--; goDir = true; }else{ lastHit[i][2] = 0; lastHit[i][6]--; } } } else if ((startX - lastHit[i-1][0]) < 0){ System.out.println("X - 1"); if (lastHit[i][3] == 1){ if ((startX - 1) >= 0){ startX--; lastHit[i][3] = 0; lastHit[i][6]--; goDir = true; }else{ lastHit[i][3] = 0; lastHit[i][6]--; } } } if ((startY - lastHit[i-1][1]) > 0){ System.out.println("Y + 1"); if (lastHit[i][4] == 1){ if ((startY + 1) <= boardHeight){ startY++; lastHit[i][4] = 0; lastHit[i][6]--; goDir = true; }else{ lastHit[i][4] = 0; lastHit[i][6]--; } } } else if ((startY - lastHit[i-1][1]) < 0){ System.out.println("Y - 1"); if (lastHit[i][5] == 1){ if ((startY - 1) >= 0){ startY--; lastHit[i][5] = 0; lastHit[i][6]--; goDir = true; }else{ lastHit[i][5] = 0; lastHit[i][6]--; } } } } }

Last edited by Lang : 11-09-2007 at 07:49 PM.
Reply With Quote
Sponsored Links