• Post Reply Bookmark Topic Watch Topic
  • New Topic

Using loops in Java  RSS feed

 
Brett Banich
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm new to java and I need to loop this code. I want the loop to end when one of these things happen. How can I do this, or what kind of loop should I use? ("blank" or "null" to exit; '#' to change key)

 
Pete Letkeman
Ranch Foreman
Posts: 914
26
Android Chrome IntelliJ IDE Java MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If this is an loop that will always execute at least once then I suggest that you use a do while loop.
Here is the Oracle Java tutorial on control flow statements
https://docs.oracle.com/javase/tutorial/java/nutsandbolts/flow.html
and here is the part about do while and while loops
https://docs.oracle.com/javase/tutorial/java/nutsandbolts/while.html

I think that this should help point you in the correct direction.
 
Brett Banich
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pete Letkeman wrote:If this is an loop that will always execute at least once then I suggest that you use a do while loop.
Here is the Oracle Java tutorial on control flow statements
https://docs.oracle.com/javase/tutorial/java/nutsandbolts/flow.html
and here is the part about do while and while loops
https://docs.oracle.com/javase/tutorial/java/nutsandbolts/while.html

I think that this should help point you in the correct direction.


I appreciate the response. Ill read up on while loops.
 
Pete Letkeman
Ranch Foreman
Posts: 914
26
Android Chrome IntelliJ IDE Java MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Brett Banich wrote:I appreciate the response. Ill read up on while loops.

Well that's what we are here for to help each other out.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!