Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-09-2007, 07:47 PM
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.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-09-2007, 09:41 PM
ShoeNinja's Avatar
Senior Member
 
Join Date: Oct 2007
Posts: 123
ShoeNinja is on a distinguished road
Send a message via AIM to ShoeNinja
Without knowing more of what is going on, the only thing that I can think of is that startX - lastHit[i-1][1] and startY - lastHit[i-1][1] might be equal to 0. This is a case for which you are not checking. I would add a catch-all else to your if else's just to make sure.

From what you have said before, it sounds like you have gotten it to print 'true' at some point. If that is the case, I'm not really sure what to tell you.

Another minor detail; your main if isn't necessary. It is reiterating one of your loop conditions. You might have put it in there for testing though. I have no idea.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 11-09-2007, 09:47 PM
Member
 
Join Date: Nov 2007
Posts: 8
Lang is on a distinguished road
I did put the main if there for testing. Also the reason I don't have an else is because either the startX or startY are going to be different, no matter what. However, I'll add it in and see what happens.

Thanks for taking a look! Ill post the result of the changes soon.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 11-09-2007, 10:07 PM
Member
 
Join Date: Nov 2007
Posts: 8
Lang is on a distinguished road
ShoeNinja, you were right. Those if statements evaluated to 0. I'll fix 'er up now.

Thanks for all your help.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 11-09-2007, 11:01 PM
ShoeNinja's Avatar
Senior Member
 
Join Date: Oct 2007
Posts: 123
ShoeNinja is on a distinguished road
Send a message via AIM to ShoeNinja
Sweet man! Glad you got it figured out.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
iterator issues orchid New To Java 2 08-12-2008 03:43 PM
Issues with Jva I.O Annatar01 New To Java 0 02-08-2008 03:16 AM
Array issues Neo82 New To Java 1 12-31-2007 05:22 AM
Compatibility issues with IE7 Aneesha New To Java 7 11-30-2007 07:46 AM
Variable issues! Alex89 New To Java 1 11-07-2007 09:51 PM


All times are GMT +3. The time now is 10:10 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org