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

Louis Mott
Louis Mott
1,923 Points

Java Looping until the value passes

not sure why im getting error "Variable response may not have been initialized"

Example.java
// I have initialized a java.io.Console for you. It is in a variable named console.
String response;
boolean isValidResponse;
do {
  console.readLine("Do you understand do while loops?   ");
  isValidResponse = (response.equalsIgnoreCase("Yes"));
  if (isValidResponse) {
    console.printf("Great!");
      }
    } while (isValidResponse);

3 Answers

Florian Tรถnjes
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Florian Tรถnjes
Full Stack JavaScript Techdegree Graduate 50,856 Points

Hey Louis,

you are reading a line from the console but are not assigning it to the variable 'response'.

try this:

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

Kind Regards, Florian

Where did you get the "yes" and if statement from?