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

do while loop

how to prompt a user in a do while loop

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

boolean response = no;
do
{
  response = console.readLine("do you understand do while loops?");


}while(response == no);

1 Answer

Alex Bratkovskij
Alex Bratkovskij
5,329 Points

Hi santosh,

First of all I can see that you have two different variables witht he same name, String response and boolean response.

Why not assign the value that we get from console.ReadLine() to the response and then check if it is "No" ?

It will make your code look much cleaner and simplier. Make sure that you carefully read the task.

// here we declare response as empty String.

String response = "";

//then we start do while loop
do{
 // here we assign console.ReadLine(""); to response which we had declared earlier 
}
// now its time for condition
while(  ); //make sure to check if entered string is not equal to "No"

I can provide full solution but then it wouldnt be as interesting to finish figuring it out yourself :)

Have fun, Alex

nice explanation ........thank you......