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 trialJuanchi Tognini
1,042 PointsCan someone please help me? I don't know what to do.
I have watched the video twice but I still don't know how to do this task. The question is asking me: "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." Could someone please explain me how to do this? -Thank you very much
// 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
Bartosz Piechaczek
1,876 PointsOk, so you want to know if user understands while loops, and you will ask him this question util he will say "yes". So first of all you have to declare a string variable named response and initialize it to store "no". Then you have to create a while loop. This is how it looks like : while(condition) {block of code}; Your condition is (response!="yes"); Now inside the loop you have to ask user a question and store his answer in the variable named response. while(response!="yes"){ response = console.readLine("Do you understand while loops?"); } This is what I'm talking about.
I hope now you understand everything.
Have a nice day!
Gonzalo Torres del Fierro
Courses Plus Student 16,751 PointsString response ; do{ response = console.readLine("Do you understand do while loops? %n"); } while (response.equalsIgnoreCase("No")); // this can be other option as a Solution, by the way you can use just equals, and not the equalsIgnoreCase, just i did here
Juanchi Tognini
1,042 PointsJuanchi Tognini
1,042 PointsThank you very much! Have a nice day! :)