Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Having trouble getting to while loop

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 119
Oracle Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this code is little buggy..
you shouldn't use while loop that way.. try coding as simple..
 
Angela Li
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you give me a suggestion on what to use besides a while loop?
 
Ranch Hand
Posts: 479
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 87
Android Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where did you declare variable point?
Before while(), instead of if{} you can try switch(total){}.
This may help.
 
reply
    Bookmark Topic Watch Topic
  • New Topic