• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Problems with "while " loops

 
Ranch Hand
Posts: 210
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 210
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 32
Eclipse IDE Objective C Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
did the fix , only for the pickProgram(), or for all the methods ..
 
mike ryan
Ranch Hand
Posts: 210
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!!

 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!