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 trial

Java Java Basics Perfecting the Prototype Looping until the value passes

Brian Maimone
PLUS
Brian Maimone
Courses Plus Student 1,644 Points

Too 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);

Example.java
// 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
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Rob Bridges
Full Stack JavaScript Techdegree Graduate 35,467 Points

Hey 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.

Try this:

Example.java
// 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
PLUS
Brian Maimone
Courses Plus Student 1,644 Points

Tried 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
STAFF
Craig Dennis
Treehouse Teacher

Super 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 ;)