• Post Reply Bookmark Topic Watch Topic
  • New Topic

Why is my while loop not working?  RSS feed

 
David Vach
Ranch Hand
Posts: 105
3
Chrome Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I'm trying to do is for my loop to end when the user types yes, for it to print out the song when the user types no, and for it to prompt the user to retype yes or no if there is a spelling error. However, only yes or no work, and when I make a spelling error, it ignores any all other code and skips right to my last while loop, which then doesn't work if I prompt it with continue, which is meant to repeat this last song in my class. If i type yes, it exits like its supposed to. However, it does not recognize continue as being okay and calls it a mistake, not allowing me to print out my code at all and repeat it. I am rather new to java so please stay with me. I have tested this last loop in my simplified class, where it is the only while loop and it works, 100% of the time when its supposed to. Im convinced its my other loops causing the problem, but I don't know what that problem is. In short, last loop works when in simplified class, not in the final project which is posted below. Here is my code:


 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have a number of while loops. Can you give us the line number of the one that fails?
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have a 180‑line main method. The main method shou‍ld contain a single statement. (No, that example does not contain two statements.) That method is a mass of repeated code which ought to be divided up.
You are telling the user to enter yes and then asking whether the input equals "continue". Are you sure that is going to work?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!