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

Johnathan Mullen
Johnathan Mullen
1,868 Points

Do while loop

I need help figuring out what my error message means and am I going in the right direction on this question

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?");
do {
console.printf(response);
}
  while(response.equalsIgnoreCase("no"));

1 Answer

andren
andren
28,558 Points

In your code you tell Java to run the loop as long as the response variable equals "no", but within that looping code you only print the variable, you don't have any code that might change what that variable holds, meaning the loop will never end if the user enters "no" during the prompt.

You are definitively on the right track, but you need to have a prompt within the loop that asks the question again and stores the result back into the response variable. That is the point of the loop, to repeatedly ask the question until a response other than "no" is given.

Johnathan Mullen
Johnathan Mullen
1,868 Points

What if I replace the console.printf(response); with console.printf(console.readLine("Do you understand do while loops?");