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

I can't figure out an error I found in my syntax.

It says that the variable response is already described in a method I don't understand that is called run(). If someone could tell me where I went wrong that would be very helpful.

Example.java
// I have initialized a java.io.Console for you. It is in a variable named console.

String response;
do{
String response = console.readLine("Do you understand do while loops? ");
}while (response.equalsIgnoreCase("no"));

2 Answers

Jacob Bergdahl
Jacob Bergdahl
29,118 Points

You need to remove the "String" keyword from your loop. The reason why is because you've already declared the variable before the loop ("String response"), so every time you want to use "response" after that, you will simply call it without using "String".

Thanks so much for the help!

Enrique Munguía
Enrique Munguía
14,311 Points

You are declaring twice the variable response, within the do loop you can use it without typing the type String again

String response;
do{
    response = console.readLine("Do you understand do while loops? ");
}while (response.equalsIgnoreCase("no"));