Bookmark Topic Watch Topic
  • New Topic

Ending a loop

 
Joey McGee
Greenhorn
Posts: 27
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 187
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator
break statement would do the job, of course in your case combined with proper check for user input.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47229
52
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
    Bookmark Topic Watch Topic
  • New Topic