Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Basics Perfecting the Prototype Looping until the value passes

Joe Di Trolio
Joe Di Trolio
3,367 Points

I can't see where I'm going wrong :\

I've tried everything but am unable to see what I am doing wrong with regards to this question.

"Now continually prompt the user in a do while loop. The loop should continue running as long as the response is No. Don't forget to declare response outside of the do while loop."

My attempt is attached:

Would someone please shine some light on my predicament and help me progress to the end of the course?

Thank you! : )

Example.java
// I have initialized a java.io.Console for you. It is in a variable named console.

String response;
do {
 response = console.readLine("Do you understand do while loops?  ");
 if (response.equalsIgnoreCase("No"));
 response = console.readLine("Do you understand do while loops?  ");
 } while(response.equalsIgnoreCase("No"));
 response = console.readLine("Do you understand do while loops?  ");

3 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! Parts of your code are correct. In fact, if I were to selectively delete parts of it, it would pass. Take a look and see how close you are/were :smiley:

String response;
do {
  response = console.readLine("Do you understand while loops?");
} while (response.equalsIgnoreCase("no"));

I declare my string. Then I ask the user for an answer. While the answer is equal to "no" (ignoring the case), I ask them again. Hope this helps! :sparkles:

Justin Carothers
Justin Carothers
12,598 Points

You don't need the if statement or line 9. You just need to state what this program will do (repeat it self) while the response is "no".

String response;
do {
  response = console.readLine("Do you understand do while loops?");
}  while (response.equalsIgnoreCase("No"));
Joe Di Trolio
Joe Di Trolio
3,367 Points

Thank you very much for your replies Jennifer and Justin, it really did help me a lot! Seems that I was way over complicating things. :smiley: