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

Philip Schultz
Philip Schultz
11,437 Points

I am asked to make a simple do while loop that ask's the user a question. If the answer is no then repeat.

please help i don't see why the code is not working.

Example.java
// I have initialized a java.io.Console for you. It is in a variable named console.
String response;
boolean wrong;
do {
 response = console.readLine("Do you understand do while loops?");
  wrong=response.equalsIgnoreCase("no");

  if (wrong) {
    console.printf("This will repeat untill answer is yes");

}

while (wrong);


}

1 Answer

Amy Tucker
Amy Tucker
13,273 Points

It looks like your closing brackets are a bit off. The last closing bracket should come before the while(wrong) statement instead of after.

do {
} while (wrong);
Amy Tucker
Amy Tucker
13,273 Points

That didn't format quite the way I thought it would but I hope that makes sense :)

Philip Schultz
Philip Schultz
11,437 Points

yup that was it. Thank you Amy.