This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Ending a loop Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic

Ending a loop

Joey McGee

Joined: Nov 22, 2012
Posts: 27
Below is the code where I've created a loop and am trying to code it to end if the user types in no... If anyone could help me with this it would be greatly appreciated.
Emanuel Kadziela
Ranch Hand

Joined: Mar 24, 2005
Posts: 187
Kemal Sokolovic

Joined: Jun 19, 2010
Posts: 825

break statement would do the job, of course in your case combined with proper check for user input.

The quieter you are, the more you are able to hear.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 43923
If you are going to have that do‑while loop, you are far better writing it like thisYou will have to check whether answer is still in scope if it is declared inside the loop.
I agree. Here's the link:
subject: Ending a loop
jQuery in Action, 3rd edition