Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Java Basics Perfecting the Prototype Looping until the value passes

Robert Zaharia
PLUS
Robert Zaharia
Courses Plus Student 579 Points

Hi ! I can't find the mistake . I have to make a do while loop that should continue as the response is "No".

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

Example.java
// I have initialized a java.io.Console for you. It is in a variable named console.
String response;
do  { console.readLine("Do you understand do while loops?")}
while(response.equals("no"))

2 Answers

Hi Robert,

Your code is good. But one thing; you're asking for user input using readLine but you need to assign the result of that into response. So add response = in front of your console.readLine line.

Oh, and you may need a semi-colon right at the end of the while(response.equals("No")); and you certainly need one at the end of the line inside the while loop!. Plus "No" may need to be uppercase N too.

Sorry; I'm on my tablet and don't have a machine to check all that.

Steve.

Zack Mowrer
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Zack Mowrer
Full Stack JavaScript Techdegree Graduate 62,350 Points

You are very close. There are just two things wrong with this.

First, a simple syntax error. you need to end the do while loop with a semicolon, like this:

while(response.equals("no"));

Second, you need to store the result of console.readLine into the response variable, like this:

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

Here's a version that I have tested that should work:

// I have initialized a java.io.Console for you. It is in a variable named console.
String response;
do {
  response = console.readLine("Do you understand do while loops?");
} while (response.equals("No"));