This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Having trouble getting to while loop Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Having trouble getting to while loop" Watch "Having trouble getting to while loop" New topic
Author

Having trouble getting to while loop

Angela Li
Greenhorn

Joined: Nov 04, 2011
Posts: 12
I am writing a part of the craps game, and I am having trouble getting from the else loop to the while loop. My method just seems to ignore the while loop but I need the while loop to work.
Atul Darne
Ranch Hand

Joined: Jul 05, 2009
Posts: 118

this code is little buggy..
you shouldn't use while loop that way.. try coding as simple..


Regards, Atul.
I came to this world on a Learner's License
Angela Li
Greenhorn

Joined: Nov 04, 2011
Posts: 12
Can you give me a suggestion on what to use besides a while loop?
Ralph Cook
Ranch Hand

Joined: May 29, 2005
Posts: 479
My suggestion is to take a step back and describe what you want this routine to do.

Your current code tests the parameter total for the values 7, 11, 2, 3, and 12. If total is not one of those values, you set point to total, firstRoll to false, and the return out of the routine; so unless total is one of those values, you are not going to reach your while loop.

You also have "while (<condition>) { return 0; }" -- a while loop is normally supposed to execute its body some number of times while the condition is true, but if your condition is ever true, the body of your loop returns out of the method, and that will end the loop.

I suggest that you describe in a "pseudoCode" what you want to do: use English, write a one-sentence description of the overall purpose of the routine, and then a step by step description at a low level of how it gets to that, without worrying about variables or java syntax. If you want to, you can put double slashes (//) in front of all of those so they can be comments in your routine.

Then you write your routine around them -- just leave the comments in place and write the statements to do the steps you want to do. They will help you keep "on track" for what you want to do, and will be excellent help for those of us willing to help you when you show it to us later.

rc
Aniket S. Kulkarni
Ranch Hand

Joined: Jun 15, 2011
Posts: 87

Where did you declare variable point?
Before while(), instead of if{} you can try switch(total){}.
This may help.


Aniket Kulkarni
Oracle Certified Professional, Java SE 6 Programmer.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Having trouble getting to while loop
 
Similar Threads
Annoying Error
an int and a string.
Help with this code
Head First Java (2nd Ed.) p. 112
Trouble changing variable within loop