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 trialZachary Menendez
454 PointsDon't understand why I can't get this do while loop to work I did the same thing as the guy in the video and no luck.
i'm trying to make this work but i'm hsving no luck at all I don't understand what i'm doing wrong I need to make it keep running if someone says no.
// I have initialized a java.io.Console for you. It is in a variable named console.
String response;
do {
response = console.readLine("Do you understand do while loops");
boolean isAnswerValid = (response.equalsIgnoreCase("yes"));
if (isAnswerValid) {
console.printf("you do understand do while loops");
} while(isAnswerValid);
}
Gábor Molnár
9,928 PointsGábor Molnár
9,928 PointsThe problem is that you need to add while to the do statement and not to the if . So a do-while loop looks like this correctly:
Here is the solution for your problem:
This loop firstly runs and asks for a question and wait for an input. Then it will be running until the condition in the while won't be false.