• Post Reply Bookmark Topic Watch Topic
  • New Topic

stuck in an infinate loop  RSS feed

 
Deyna Cegielski
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Point sPt = new Point(0,0);
Point cPt = new Point(sPt.x,sPt.y);

while(isSolvable == false){

if((cPt.x + 1) <= 29){//check to see if point u want to go to with is valid, if so, goto it, else go down

Point nPt = new Point(cPt.x + 1,cPt.y);
if(maze[nPt.x][nPt.y] == "t"){

maze[nPt.x][nPt.y] = "v";
cPt = nPt;
temp = true;

}

}

the inner loop isnt getting exectued at all so the point is no updating to the new point, so the if startment keeps running on the same point over and over. any ideas?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see any way that isSolveable is ever set to true, so as written, the loop will never terminate.

I don't understand the logic here, really, but if you need to break out of a loop at some point, you can use the "break" statement.

Finally, note that you oughtn't ever write "if (isSolveable == false)". Instead, write "if (!isSolveable)." Likewise, prefer "if (isSolveable)" to "if (isSolveable == true)." The forms I recommend are shorter, easier to understand, and less error-prone.
 
Jimmy Die
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

First, it's best to use the UBB code 'code' button for your code. When you post just scroll down a little bit and you see them next to the smiley faces...

When we do this the code you inserted on your post doesn't have a inner loop, unless your outer loop is your inner loop and you haven't posted the closing brackets...

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!