This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori 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

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
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: 44556
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
It's not a secret anymore!