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

Leen Leenaerts
Leen Leenaerts
1,096 Points

I don't see what I am doing wrong

it says response is already defined in the loop but I don't see why that is a problem. I thought it only should be defined before you run the loop which is the case.

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

2 Answers

Rob Bridges
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Rob Bridges
Full Stack JavaScript Techdegree Graduate 35,467 Points

Hey there Leen,

You're code is close but you're creating your variable response twice, it was already created when you did

String response;

Just remove the "String" declaration in do while loop and your code passes. Should look like

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

Shoot back if this doesn't help.