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

What is wrong with my program?

I do not see what is wrong with my code

Example.java
// 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?");
String response;
do (
  response = ("Do you understand do while loops?");
  if(noun.equalsIgnoreCase("No"));



) while

1 Answer

Michael Hess
Michael Hess
24,512 Points

Hi Will,

You're pretty close, but there are a couple of things you will probably want to change.

The do-while loop is a post-test loop -- which means that the condition we are testing is tested after the the code in the loop body. This also means that the code in the loop body is executed at least once.

The if-statement can be removed and since the response variable has already been declared, we can set it equal to console.readLine in the loop body -- and "yes" or "no" will be stored in the response variable. The loop will repeat if "no" is entered.

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

The above code will get you past the first two tasks. If you have any further questions feel free to ask! Hope this helps!