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 trialSawyer B
204 Pointslogic of do while loops
I'm stuck on a very simple question and getting lots of errors. Is the issue with improper use of the String.equals the logic of my loop?
// 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?");
do while(response.equals("No"));
{
console.readLine("Do you understand do while loops?");
}
2 Answers
Ronald Williams
Java Web Development Techdegree Graduate 25,021 PointsFirst of all, I can reassure you that do while loops are not that simple when first learning programming. It just takes some time and with enough practice you will be able to master them! Here is one way to solve the challenge and why that code did not compile.
String response = "no";
do {
response = console.readLine("Do you understand do while loops?");
} while (response.equalsIgnoreCase("no"));
It is just a matter of separating your do and while. A do while loop will be as follows:
do {
statement(s)
} while (expression);
Converted to an answer - Dane E. Parchment Jr. (Moderator)
Edvardas Markevicius
Courses Plus Student 9,193 PointsThe usage of equals method is correct, the problem is the usage of do-while loop. You clearly didn't understand the logic behind do-while loops, click on the link below, it will explain to you how do-while loops work compared to while loops and also there is an example , hope this helps! :)
Converted to an answer - Dane E. Parchment Jr. (Moderator)
Sawyer B
204 PointsSawyer B
204 PointsString.equals or the logic* I meant to say.