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 trialKyudong Lim
528 PointsI can't get pass the task 2. please help
Here is the task: 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 = console.readLine("Do you understand while loops? ");
2 Answers
Michael Hess
24,512 PointsHi Kyudong Lim,
The do-while loop will keep asking "Do you understand do while loops?" until yes is typed then the do-while loop is exited. The following code will guide you through task 2 of this challenge:
//Declare a String variable named response
String response;
// The do while loop keeps asking the same question until "yes" is entered
//So we want to keep repeating when "no" is typed
// Exit the loop when "yes" is entered
do{
response = console.readLine("Do you understand do while loops?"); // "yes" or "no" is stored in the response variable
// when someone types "no" the loop repeats
// when someone types "yes" the loop is exited
}while(response.equalsIgnoreCase("no"));
If you have any other questions feel free to shout them out on the forum! Hope this helps!
Michael Makali'i Fernandez
8,090 Pointsyou need to create a loop that continually polls a response from the user. It would look something like the following:
String response; // this is declared outside of the loop so that this variable can be seen by while do { response = console.readLine("Do you understand while loops?"); } while (response == "No");
not sure if you need to take whether the letters should be upper or lower case into consideration for this task, but that may be important. You could also use the equals() method to check if response is equal to No.