| Author |
Problems with "while " loops
|
mike ryan
Ranch Hand
Joined: Aug 08, 2010
Posts: 210
|
|
Hi,
I am currently having a problem with this while loop and hope someone can help..
when i run this it works just once correctly (goes to the switch/case and runs the called method), then goes continually back to the choice menu when i pick the same choice again, without running the switch statements?I seem to have lots of problems with
"while loops" and i actually thought i got the idea!?!
ok here is the code, i imagine it is something simple but i am not finding it...
Thanks in advance for any help !!
Mike
|
 |
pete stein
Bartender
Joined: Feb 23, 2007
Posts: 1561
|
|
I don't see anything obviously wrong with your code, but must admit that it's hard to read your code as your indentation formatting is somewhat arbitrary. It's also difficult to test it as it is missing some code such as the Fernseher class. I've added a trivial Fernseher class for testing purposes and have re-formatted the code:
If you're still having problems, then create and post a small compilable program and also add some println statements to help debug your program.
Much luck!
|
 |
mike ryan
Ranch Hand
Joined: Aug 08, 2010
Posts: 210
|
|
hi pete,
Thanks for the quick response;) i found the problem, in my fernseher class i had the boolean variable "weiter" as a static instance variable.I moved it to the method and it worked ;)
|
 |
pete stein
Bartender
Joined: Feb 23, 2007
Posts: 1561
|
|
mike ryan wrote:hi pete,
Thanks for the quick response;) i found the problem, in my fernseher class i had the boolean variable "weiter" as a static instance variable.I moved it to the method and it worked ;)
I'm glad that you found the cause of your problem and fixed it. Also, thanks for sharing this fix for all to see!
For what it's worth though, there's no such thing as a "static instance" variable. If it's a variable on the class level, then either it's a static variable or it's an instance variable. In your case the problem was more of using an instance field/variable rather than a local variable.
|
 |
Kiaamaa Liammes
Ranch Hand
Joined: Oct 03, 2009
Posts: 32
|
|
|
did the fix , only for the pickProgram(), or for all the methods ..
|
SCJP ,SCWCD
|
 |
mike ryan
Ranch Hand
Joined: Aug 08, 2010
Posts: 210
|
|
to pete,
Thanks for the clarification, although i thought a Class variable, is an instance variable and it was static.But i just started with Objects so i am still trying to learn the theory behind it,although
there seems to be allot of disgussions as far as what different theories people interpret for rules in JAVA, gets a bit confusing;)
to Kiaamaa,
That was up to this point the only while loop i had, if i had more i am sure they would have had similar problems as that variable is for the entire class then (i believe).
Thanks again to pete and i learned something here once again, so that is really the important thing and also why i look at all the threads here because i can learn allot from others mistakes and quetions,
that is why i find this forum so GREAT!!
|
 |
 |
|
|
subject: Problems with "while " loops
|
|
|