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 trialBrian Maimone
Courses Plus Student 1,644 PointsToo many loops detected, check your while condition error
Can't figure out what done wrong. Appreciate help.
Boolean answerIsNo; do { String response = console.readLine("Do you understand do while loops?: "); if (response.equals("No")); { answerIsNo = true;} } while (answerIsNo);
// I have initialized a java.io.Console for you. It is in a variable named console.
Boolean answerIsNo;
do {
String response = console.readLine("Do you understand do while loops?: ");
if (response.equals("No")); {
answerIsNo = true;}
} while (answerIsNo);
4 Answers
Rob Bridges
Full Stack JavaScript Techdegree Graduate 35,467 PointsHey there Isiah was close on this, just the small error of declaring response with a String in front of it, thought you were trying to declare the same variable twice. Try the code below.
String response;
do {
// For the first task: (Delete 'String' on the second task),
response = console.readLine("Do you understand do while loops?");
} while (response.equalsIgnoreCase("No"))
console.printf("Because you said %s, you passed the test!", response);
Thanks, feel free to shout if there's any trouble with this.
ISAIAH S
1,409 PointsTry this:
// I have initialized a java.io.Console for you. It is in a variable named console.
String response;
// The second,
do {
// For the first task: (Delete 'String' on the second task),
String response = console.readLine("Do you understand do while loops?");
// The second,
} while (response.equals("No"));
// And the third:
console.printf("Because you said %s, you passed the test!", response);
Brian Maimone
Courses Plus Student 1,644 PointsTried your example but I'm getting error: variable response is already defined in method run() String response = console.readLine("Do you understand do while loops?: "); In the exercise it requires response to be declared as a string variable outside the do loop. Thoughts?
Craig Dennis
Treehouse TeacherSuper close! Note your unneeded semicolon:
if (response.equals("No")); {
Every time through the loop you were setting it because that line ends right there. It probably will work better ;)