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

code not running?

initialisation error

Example.java
String response;
{
do
{
   console.readLine("Do you understand do while loops?");  
}while(response.equalsIgnoreCase("No"));
}
Deividas Strioga
Deividas Strioga
12,851 Points

Hey Sha Sud, next time please give more info, like which step of the task you are on. You get initialization error because you declare String response, but you do not initialize it - do not give it a meaning. In a while statement you are checking if your String response is equal to "no", but you never gave it a meaning. You should put an answer from readLine to the String response. Tell me how it goes.

1 Answer

The code you posted has issues as below:

  1. The first pair of curly braces are redundant.
  2. After reading the user input, it is not being assigned to "response" String.

Here is a solution:

String response;

do {
  response = console.readLine("Do you understand do while loops?");
} while (response.equals("No"));

console.printf("Because you said %s, you passed the test!", response);