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

The loop should continue running as long as the response is No.

I've messed with this so long I don't know what is my work and what are suggestions from others. The Preview says it's fine, but Bummer ticker says be sure it keeps looping while the answer is No. I can't see what I'm doing wrong. Please help. Thanks.

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.

String response = ""; boolean isNo; do { console.readLine("Do you understand do while loops? "); isNo = (response.equalsIgnoreCase("No")); if (isNo) { console.printf("Try again. \n"); } } while(isNo);

Example.java
// I have initialized a java.io.Console for you. It is in a variable named console
  String response = "";
  console.readLine("Do you understand do while loops?  ");

2 Answers

Fahad Mutair
Fahad Mutair
10,359 Points

hello, he's asking you loop when u get No response by using do while loop and you can achieve that like this code.

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

Hi fahad mutair, On the 4th line, why is there two ==?

Fahad Mutair
Fahad Mutair
10,359 Points

Hi Lee Preslan , 4th line means if the condition response equals to No continue Looping and it will keep asking until the condition is false

while(response=="No");

Thank you!!