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 trialAnil kumar N
658 PointsPrompt the user with the question "Do you understand do while loops?" Store the result in a new String variable named re
the compiler is not compiling. Showing to reload
// I have initialized a java.io.Console for you. It is in a variable named console.
String response= "Do you understand do while loops?";
do {
console.printf("%s",response);
} while (response==response);
1 Answer
michaelcodes
5,604 PointsHi there! So for part 1 of the challenge we want to prompt the user with the question of whether they understand do-while loops and store it in the variable "response". This line you have here:
String response= "Do you understand do while loops?";
This is storing the String "Do you understand do while loops?" inside the variable response. Instead we want to store the result of the console.readLine method inside the variable as such:
String response = console.readLine("Do you understand do while loops?");
For part 2 of the challenge we want to continuously prompt the question so long as response is not equal to "No". This would look like the following:
String response; //Declare variable outside of do-while scope
do {
//keep asking if they understand do-while loops If answer is "No"
response = console.readLine("Do you understand do while loops?");
} while (response=="No"); // If response is NOT equal to "No", stop looping
Hope this helps! take care and happy coding :)
Anil kumar N
658 PointsAnil kumar N
658 Pointsonce again thanks sir. I was thinking too much. It was just simple :)