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 trialtrina joy
6,525 Pointssolve do-while loop
where have i gone wrong here?
// I have initialized a java.io.Console for you. It is in a variable named console.
String response;
boolean No;
do {
response = console.readLine("Do you understand do while loops?");
No = (response.equalsIgnoreCase("No"));
if (No){
console.printf("the answer is no");
}
} while (No);
}
1 Answer
Andrew Dummer
6,885 PointsIn your if statement, instead check if response equals "No" (if(response == "No")), and if the response is "No" you should additionally change your boolean No to "true" inside of the brackets of the if statement. Finally, have the boolean No equal "false" at the beginning of your do-while loop instead of No = (response.equalsIgnoreCase("No"));