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 trialGedeon Christ
413 PointsNow continually prompt the user in a do while loop. The loop should continue running as long as the response is No. Don'
do (userQuestion = console.readLine("Do you understand do while loops? ")) { if (response.equalsIgnoreCase("no") { userQuestion = console.readLine("Do you understand do while loops? ") } }
// I have initialized a java.io.Console for you. It is in a variable named console.
String userQuestion = console.readLine("Do you understand do while loops? ");
String response = userQuestion;
do (userQuestion = console.readLine("Do you understand do while loops? ")) {
if (response.equalsIgnoreCase("no") {
userQuestion = console.readLine("Do you understand do while loops? ")
}
}
2 Answers
Steven Parker
231,269 PointsYou've gotten a little off-track, here's a few hints:
- you won't need to ask the question when you first declare the variable
- there should be nothing between the "do" and brace that starts the code block
- you can assign "response" directly when you answer the question (you won't need "userQuestion")
- you still need the "while" to go with the "do"
- the conditional test (currently in an "if") can be placed in the "while"
Gedeon Christ
413 PointsHi Steven Parker. Thank you for your response. i will try again.
Steven Parker
231,269 PointsGedeon Christ — Write again if you still have trouble. Otherwise you can mark a question solved by choosing a "best answer".
Happy coding!